Add test for when specialization types conflict

This commit is contained in:
Ayaz Hafiz 2022-04-12 19:01:36 -04:00
parent cf1a6691dd
commit 67b5ab7fe7
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 44 additions and 4 deletions

View file

@ -1319,10 +1319,8 @@ fn check_ability_specialization(
.filter(|mia| mia.ability == root_data.parent_ability) .filter(|mia| mia.ability == root_data.parent_ability)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
ability_implementations_for_specialization.dedup(); ability_implementations_for_specialization.dedup();
debug_assert_eq!(
ability_implementations_for_specialization.len(), 1, debug_assert!(ability_implementations_for_specialization.len() == 1, "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization");
"If there's more than one, the definition is ambiguous - this should be an error"
);
// This is a valid specialization! Record it. // This is a valid specialization! Record it.
let specialization_type = ability_implementations_for_specialization[0].typ; let specialization_type = ability_implementations_for_specialization[0].typ;

View file

@ -9577,4 +9577,46 @@ I need all branches in an `if` to have the same type!
), ),
) )
} }
#[test]
fn ability_specialization_conflicting_specialization_types() {
new_report_problem_as(
indoc!(
r#"
app "test" provides [ eq ] to "./platform"
Eq has
eq : a, a -> Bool | a has Eq
You := {}
AndI := {}
eq = \$You {}, $AndI {} -> False
"#
),
indoc!(
r#"
TYPE MISMATCH
Something is off with this specialization of `eq`:
9 eq = \$You {}, $AndI {} -> False
^^
This value is a declared specialization of type:
You, AndI -> [ False, True ]
But the type annotation on `eq` says it must match:
You, You -> Bool
Tip: Type comparisons between an opaque type are only ever equal if
both types are the same opaque type. Did you mean to create an opaque
type by wrapping it? If I have an opaque type Age := U32 I can create
an instance of this opaque type by doing @Age 23.
"#
),
)
}
} }