fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Either support or forbid qualified type parameters

Open fridis opened this issue 1 year ago • 0 comments

Check this example that uses qualified type parameters in d, e, f ande:

test_generics is

  a(X, Y type,
    v X,
    w Y,
    o option X,
    a Sequence Y) is
    say (type_of v)
    say (type_of w)
    say (type_of o)
    say (type_of a)

  b(X, Y type,
    v (b X Y).X,
    w (b X Y).Y,
    o option   (b X Y).X,
    a Sequence (b X Y).Y) is
    say (type_of v)
    say (type_of w)
    say (type_of o)
    say (type_of a)

  c(X, Y type,
    v (test_generics.c X Y).X,
    w (test_generics.c X Y).Y,
    o option   (test_generics.c X Y).X,
    a Sequence (test_generics.c X Y).Y) is
    say (type_of v)
    say (type_of w)
    say (type_of o)
    say (type_of a)

  d(X, Y type,
    v (d u64 bool).X,
    w (d f32 u8  ).Y,
    o option   (d u64 bool).X,
    a Sequence (d f32 u8).Y) is
    say (type_of v)
    say (type_of w)
    say (type_of o)
    say (type_of a)

  e(X, Y type,
    v (test_generics.e int uint).X,
    w (test_generics.e unit void ).Y,
    o option   (test_generics.e TRUE FALSE).X,
    a Sequence (test_generics.e unit void ).Y) is
    say (type_of v)
    say (type_of w)
    say (type_of o)
    say (type_of a)

  _ := a String i8 "bla" -3 nil []
  _ := b String i8 "bla" -3 nil []
  _ := c String i8 "bla" -3 nil []
  _ := d String i8 3333333 33 nil []
  _ := e String i8 (int 3) (panic "") nil []

But they all result in errors

 > ./build//bin/fz test_generics.fz 

/home/fridi/fuzion/clean/fuzion/test_generics.fz:54:20: error 1: Incompatible types when passing argument in a call
  _ := b String i8 "bla" -3 nil []

Actual type for argument #1 'v' does not match expected type.
In call to          : 'test_generics.b'
expected formal type: '(test_generics.this.b String i8).X'
actual type found   : 'String'
assignable to       : 'String'
for value assigned  : '"bla"'
To solve this, you could change the type of the target 'v' to 'String' or convert the type of the assigned value to '(test_generics.this.b String i8).X'.


/home/fridi/fuzion/clean/fuzion/test_generics.fz:54:26: error 2: Incompatible types when passing argument in a call
  _ := b String i8 "bla" -3 nil []

Actual type for argument #2 'w' does not match expected type.
In call to          : 'test_generics.b'
expected formal type: '(test_generics.this.b String i8).Y'
actual type found   : 'i32'
assignable to       : 'i32'
for value assigned  : '-3'
To solve this, you could change the type of the target 'w' to 'i32' or convert the type of the assigned value to '(test_generics.this.b String i8).Y'.


/home/fridi/fuzion/clean/fuzion/test_generics.fz:55:20: error 3: Incompatible types when passing argument in a call
  _ := c String i8 "bla" -3 nil []

Actual type for argument #1 'v' does not match expected type.
In call to          : 'test_generics.c'
expected formal type: '(test_generics.c String i8).X'
actual type found   : 'String'
assignable to       : 'String'
for value assigned  : '"bla"'
To solve this, you could change the type of the target 'v' to 'String' or convert the type of the assigned value to '(test_generics.c String i8).X'.


/home/fridi/fuzion/clean/fuzion/test_generics.fz:55:26: error 4: Incompatible types when passing argument in a call
  _ := c String i8 "bla" -3 nil []

Actual type for argument #2 'w' does not match expected type.
In call to          : 'test_generics.c'
expected formal type: '(test_generics.c String i8).Y'
actual type found   : 'i32'
assignable to       : 'i32'
for value assigned  : '-3'
To solve this, you could change the type of the target 'w' to 'i32' or convert the type of the assigned value to '(test_generics.c String i8).Y'.


/home/fridi/fuzion/clean/fuzion/test_generics.fz:56:20: error 5: Incompatible types when passing argument in a call
  _ := d String i8 3333333 33 nil []

Actual type for argument #1 'v' does not match expected type.
In call to          : 'test_generics.d'
expected formal type: '(test_generics.this.d u64 bool).X'
actual type found   : 'i32'
assignable to       : 'i32'
for value assigned  : '3333333'
To solve this, you could change the type of the target 'v' to 'i32' or convert the type of the assigned value to '(test_generics.this.d u64 bool).X'.


/home/fridi/fuzion/clean/fuzion/test_generics.fz:56:28: error 6: Incompatible types when passing argument in a call
  _ := d String i8 3333333 33 nil []

Actual type for argument #2 'w' does not match expected type.
In call to          : 'test_generics.d'
expected formal type: '(test_generics.this.d f32 u8).Y'
actual type found   : 'i32'
assignable to       : 'i32'
for value assigned  : '33'
To solve this, you could change the type of the target 'w' to 'i32' or convert the type of the assigned value to '(test_generics.this.d f32 u8).Y'.


/home/fridi/fuzion/clean/fuzion/test_generics.fz:57:21: error 7: Incompatible types when passing argument in a call
  _ := e String i8 (int 3) (panic "") nil []

Actual type for argument #1 'v' does not match expected type.
In call to          : 'test_generics.e'
expected formal type: '(test_generics.e int uint).X'
actual type found   : 'int'
assignable to       : 'int'
for value assigned  : '(int 3)'
To solve this, you could change the type of the target 'v' to 'int' or convert the type of the assigned value to '(test_generics.e int uint).X'.

7 errors.

fridis avatar Sep 20 '24 09:09 fridis