Skip to content

Commit c9a8bde

Browse files
committed
Improve error message for ambiguous polymorphic types
If a type still contains free type variables after typechecking (for example, as with "auto foo = []", the result was an assertion failure in typeck. Made it a human-readable error message instead.
1 parent 776977b commit c9a8bde

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/comp/middle/typeck.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,11 @@ mod writeback {
15701570
}
15711571
}
15721572

1573+
if (ty::type_contains_vars(fcx.ccx.tcx, local_ty)) {
1574+
fcx.ccx.tcx.sess.span_err(sp,
1575+
"Ambiguous type " + ty_to_str(fcx.ccx.tcx, local_ty)
1576+
+ "\n(Try adding more type annotations.)");
1577+
}
15731578
write::ty_only(fcx.ccx.tcx, local.ann.id, local_ty);
15741579
}
15751580

0 commit comments

Comments
 (0)