# 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
## ONLY covariance remains here
- cpt_modules.inc(mmodule.mgroup.mproject.name)
+ cpt_modules.inc(mmodule.mgroup.mpackage.name)
cpt_classes.inc(sub.mclass)
# Track if `cpt_explanations` is already decided (used to fallback on unknown)
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!?!")
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
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
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")
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
if node isa AArrayExpr then
dcp.cpt_explanations.inc("lit-array")
- else if p isa ACallExpr and (p.n_id.text == "sort" or p.n_id.text == "linearize_mpropdefs") then
- dcp.cpt_explanations.inc("generic methods (sort-method)")
- else if p isa ACallExpr and p.n_id.text == "visit_list" then
- dcp.cpt_explanations.inc("use-site covariance (visit_list-method)")
+ else if p isa ACallExpr then
+ var name = p.n_qid.n_id.text
+ if name == "sort" or name == "linearize_mpropdefs" then
+ dcp.cpt_explanations.inc("generic methods (sort-method)")
+ else if name == "visit_list" then
+ dcp.cpt_explanations.inc("use-site covariance (visit_list-method)")
+ else
+ dcp.cpt_explanations.inc("other covariance")
+ end
else
dcp.cpt_explanations.inc("other covariance")
end