Add note on the type-casting check.

This commit is contained in:
KtorZ 2024-03-13 13:25:51 +01:00 committed by rvcas
parent 8f31b45e36
commit 9127dcdd6e
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
1 changed files with 8 additions and 4 deletions

View File

@ -968,10 +968,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
None None
}; };
if kind.is_expect() && value_typ.is_or_holds_opaque() {
return Err(Error::ExpectOnOpaqueType { location });
}
// Ensure the pattern matches the type of the value // Ensure the pattern matches the type of the value
let pattern = PatternTyper::new(self.environment, &self.hydrator).unify( let pattern = PatternTyper::new(self.environment, &self.hydrator).unify(
untyped_pattern.clone(), untyped_pattern.clone(),
@ -980,6 +976,14 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
kind.is_let(), kind.is_let(),
)?; )?;
// FIXME: This check is insufficient as we need to also assert the type
// definition itself since there might be nested opaque types on the rhs.
//
// For that, we must lookup
if kind.is_expect() && value_typ.is_or_holds_opaque() {
return Err(Error::ExpectOnOpaqueType { location });
}
// If `expect` is explicitly used, we still check exhaustiveness but instead of returning an // If `expect` is explicitly used, we still check exhaustiveness but instead of returning an
// error we emit a warning which explains that using `expect` is unnecessary. // error we emit a warning which explains that using `expect` is unnecessary.
match kind { match kind {