diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 16fa71b4f9..16219d1179 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -706,7 +706,7 @@ fn can_extension_type<'a>( local_aliases, references, ); - if valid_extension_type(ext_type.shallow_dealias()) { + if valid_extension_type(shallow_dealias_with_scope(scope, &ext_type)) { ext_type } else { // Report an error but mark the extension variable to be inferred @@ -730,6 +730,29 @@ fn can_extension_type<'a>( } } +/// a shallow dealias, continue until the first constructor is not an alias. +fn shallow_dealias_with_scope<'a>(scope: &'a mut Scope, typ: &'a Type) -> &'a Type { + let mut result = typ; + loop { + match result { + Type::Alias { actual, .. } => { + // another loop + result = actual; + } + Type::DelayedAlias(AliasCommon { symbol, .. }) => match scope.lookup_alias(*symbol) { + None => unreachable!(), + Some(alias) => { + result = &alias.typ; + } + }, + + _ => break, + } + } + + result +} + pub fn instantiate_and_freshen_alias_type( var_store: &mut VarStore, introduced_variables: &mut IntroducedVariables,