Failed to infer types of variables in deep pattern matches.
Sample Code
data XX = X
data YY = Y XX
let yy = Y X
let idXX (x:XX) = x
match yy
case (Y x) = idXX x
Expected
Compiled without error.
Actual
Type error: YY is not XX
Cause
in addVarsToEnv:
newEnv[v.value] = currentValue;
newEnv[v.value] should be the type of the variable but currentValue is the type of the pattern.
data[p.tag.value][i] is the expected type from data constructor.
Fix
Assign data[p.tag.value][i] instead of currentValue to newEnv[v.value].
Problem
Failed to infer types of variables in deep pattern matches.
Sample Code
Expected
Compiled without error.
Actual
Cause
in addVarsToEnv:
newEnv[v.value] should be the type of the variable but currentValue is the type of the pattern. data[p.tag.value][i] is the expected type from data constructor.
Fix
Assign data[p.tag.value][i] instead of currentValue to newEnv[v.value].