Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report an error when a type annotation is too general #2109

Merged
merged 11 commits into from
Aug 30, 2022
2 changes: 1 addition & 1 deletion .unreleased/features/2102-polytypes-precision.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
From now on, the type checker reports an error, when the inferred type
is less specific than the type annotation, see #2109.
is more specific than the annotated type, see #2109.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class EtcTypeChecker(varPool: TypeVarPool, inferPolytypes: Boolean = true) exten

case Some((_, unifiedType)) =>
if (unifiedType.usedNames.size < operScheme.principalType.usedNames.size) {
// The number of free variables has decreased. The annotation by the user is imprecise.
// The number of free variables has decreased. The annotation by the user is to general.
val msg = s"$name's type annotation $userType is too general, inferred: $inferredType"
onTypeError(letEx.sourceRef, msg)
throw new UnwindException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ class TestEtcTypeChecker extends AnyFunSuite with EasyMockSugar with BeforeAndAf
// let @type: (a, b) => Bool;
// F(x, y) == x = y in TRUE
konnov marked this conversation as resolved.
Show resolved Hide resolved
//
// The principal type of F is (c, c) => Bool, which is more concrete than (a, b) => Bool.
// The principal type of F is (c, c) => Bool, which is more specific than (a, b) => Bool.
val eq = parser("(c, c) => Bool")
val x = mkUniqName("x")
val y = mkUniqName("y")
Expand Down