fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

ambiguous name leads to unexpected error

Open simonvonhackewitz opened this issue 11 months ago • 1 comments

Adding a feature to list.fz where an argument has the same name as an existing feature causes a strange error.

Sequence.reduce is used instead of the argument list.strange_error.reduce. Renaming the argument (e.g. to reduce_f) or calling the binary function explicitly (reduce.call x x) solves the error.

Code added to list.fz:

public list.strange_error (B type, reduce Binary A A A) =>
  match head
    nil => say "nil"
    x A => say (reduce x x)

The error:

❯ FUZION_DISABLE_ANSI_ESCAPES=true make base-only
rm -rf build/modules/base
mkdir -p build/modules
cp -rf ./modules/base build/modules
./build/bin/fz -sourceDirs=./build/modules/base/src -XloadBaseLib=off -saveLib=build/modules/base.fum -XenableSetKeyword

./build/modules/base/src/list.fz:667:28: error 1: Incompatible types when passing argument in a call
      x A => say (reduce x x)
---------------------------^
Actual type for argument #2 'f' does not match expected type.
In call to          : 'Sequence.reduce'
expected formal type: 'Binary (choice list.A (abort list.A)) list.A list.A'
actual type found   : 'list.A'
assignable to       : 'list.A'
for value assigned  : 'x'
To solve this, you could change the type of the target 'f' to 'list.A' or convert the type of the assigned value to 'Binary (choice list.A (abort list.A)) list.A list.A'.


./build/modules/base/src/list.fz:660:41: error 2: Incompatible types when passing argument in a call
          y B => res.put key (reduce y (f x))
----------------------------------------^
Actual type for argument #2 'f' does not match expected type.
In call to          : 'Sequence.reduce'
expected formal type: 'Binary (choice list.group_map_reduce.B (abort list.group_map_reduce.B)) list.group_map_reduce.B list.A'
actual type found   : 'list.group_map_reduce.B'
assignable to       : 'list.group_map_reduce.B'
for value assigned  : 'f'
To solve this, you could change the type of the target 'f' to 'list.group_map_reduce.B' or convert the type of the assigned value to 'Binary (choice list.group_map_reduce.B (abort list.group_map_reduce.B)) list.group_map_reduce.B list.A'.

2 errors.
make: *** [Makefile:652: build/modules/base.fum] Error 1

simonvonhackewitz avatar Jan 22 '25 14:01 simonvonhackewitz

Here is a smaller but similar example

 > ./build/bin/fz -e 'b(b i32->i32) => say "{b 42}"'

command line:1:26: error 1: Incompatible types when passing argument in a call
b(b i32->i32) => say "{b 42}"

Actual type for argument #1 'b' does not match expected type.
In call to          : 'b'
expected formal type: 'Unary i32 i32'
actual type found   : 'i32'
assignable to       : 'i32'
for value assigned  : '42'
To solve this, you could change the type of the target 'b' to 'i32' or convert the type of the assigned value to 'Unary i32 i32'.

one error.

This (and the original example) should better complain about the call to b (or reduce, respectively) being ambiguous and the alternatives should be b.this.b or universe.b (and strange_error.this.reduce or list.this.reduce, resp.).

fridis avatar Jan 24 '25 10:01 fridis