X-Git-Url: http://nitlanguage.org diff --git a/src/metrics/detect_covariance.nit b/src/metrics/detect_covariance.nit index c7c118d..ef403a3 100644 --- a/src/metrics/detect_covariance.nit +++ b/src/metrics/detect_covariance.nit @@ -130,8 +130,8 @@ private class DetectCovariancePhase # Returns true if the test concern real generic covariance fun count_types(node, elem: ANode, sub, sup: MType, mmodule: MModule, anchor: nullable MClassType): Bool do - sub = sub.as_notnullable - sup = sup.as_notnullable + sub = sub.undecorate + sup = sup.undecorate # Category of the target type if sub isa MGenericType then @@ -230,7 +230,7 @@ private class DetectCovariancePhase else node.debug("6.downcast {sup} to {sub}") end - else if n isa ASuperclass then + else if n isa ASuperPropdef then cpt_pattern.inc("8.subclass") else if n isa AArrayExpr then cpt_pattern.inc("9.array element") @@ -254,8 +254,8 @@ private class DetectCovariancePhase fun count_cast(node: ANode, sub, sup: MType, mmodule: MModule, anchor: nullable MClassType) do var nsup = sup - sup = sup.as_notnullable - sub = sub.as_notnullable + sup = sup.undecorate + sub = sub.undecorate if sub == nsup then cpt_cast_pattern.inc("monomorphic cast!?!") @@ -318,7 +318,7 @@ redef class TypeVisitor fun dcp: DetectCovariancePhase do return modelbuilder.toolcontext.detect_covariance_phase - redef fun visit_expr_cast(node, nexpr, ntype) + redef fun check_expr_cast(node, nexpr, ntype) do var sub = super @@ -343,7 +343,7 @@ redef class TypeVisitor return sub end - redef fun check_subtype(node: ANode, sub, sup: MType): nullable MType + redef fun check_subtype(node: ANode, sub, sup: MType, autocast: Bool): nullable MType do var res = super @@ -361,6 +361,9 @@ redef class TypeVisitor if node isa AAsCastExpr then return res end + if not autocast then + return res + end sup = supx.resolve_for(anchor.mclass.mclass_type, anchor, mmodule, true) if self.is_subtype(sub, sup) then dcp.cpt_autocast.inc("vt") @@ -371,7 +374,7 @@ redef class TypeVisitor dcp.cpt_autocast.inc("vt+pt") dcp.count_cast(node, supx, sub, mmodule, anchor) else - self.modelbuilder.error(node, "Type error: expected {sup}, got {sub}") + self.modelbuilder.error(node, "Type Error: expected `{sup}`, got `{sub}`") return null end end @@ -445,7 +448,7 @@ redef class MType # Now the case of direct null and nullable is over. # If `sub` is a formal type, then it is accepted if its bound is accepted - while sub isa MParameterType or sub isa MVirtualType do + while sub isa MFormalType do #print "3.is {sub} a {sup}?" # A unfixed formal type can only accept itself @@ -469,7 +472,7 @@ redef class MType assert sub isa MClassType # It is the only remaining type # A unfixed formal type can only accept itself - if sup isa MParameterType or sup isa MVirtualType then + if sup isa MFormalType then return false end