fuzion
fuzion copied to clipboard
Poor error message in case of unsound type parameter use in arguments
This is the underlying issue of #3613. Here is an example with unsound types
r(T type, v T) is
A ref is
f(p r A.this) b => b
b : A is
redef fixed f(p r b) => p.v
a A := b
x b := a.f (r A)
Here r contains a value of type T, so r A contains a value of type A. A.f(p r A.this) returns a value of type b, which in b is implemented to return the value v stored in p which is of type r b in this case.
Now we can call a.f (r A) where a is a ref to an instance of b that would extract a b from r A, which is impossible.
This code produces a confusing error that refers to the result type, while it should refer to the argument type.
> ../clean/fuzion/build/bin/fz unsound_parameter_type.fz
/home/fridi/fuzion/work/unsound_parameter_type.fz:10:10: error 1: Call has an ambiguous result type since target of the call is a 'ref' type.
x b := a.f (r A)
The result type of this call depends on the target type. Since the target type is a 'ref' type that may represent a number of different actual dynamic types, the result type is not clearly defined.
Called feature: 'A.f'
Raw result type: 'r A.this'
Type depending on target: 'A.this'
Target type: 'A'
To solve this, you could try to use a value type as the target type of the call or change the result type of 'A.f' to no longer depend on 'A.this'.
one error.