fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

front end mixes up inherited and outer type parameters and causes Incompatible types error

Open fridis opened this issue 2 years ago • 2 comments

This example is similar to the one in #935, but it crashes the interpreter:

inherit_outer is

  eimer(T type) is

    v T is abstract

    map(B type, f T -> B) : eimer B is
      v B is f eimer.this.v

  bucket(U type, v U) : eimer U is

  hellos => bucket "hello"
  fives => hellos.map s->s.byte_length

  say hellos.v
  say fives.v

Here the output

> ../../work/build/bin/fz inherit_outer_non_ref.fz

/home/fridi/fuzion/clean/fuzion.2/inherit_outer_non_ref.fz:8:27: error 1: Incompatible types when passing argument in a call
      v B is f eimer.this.v
--------------------------^
Actual type for argument #1 'a' does not match expected type.
In call to          : 'Function.call'
expected formal type: 'inherit_outer.eimer.map.B'
actual type found   : 'inherit_outer.eimer.T'
assignable to       : 'inherit_outer.eimer.T'
for value assigned  : 'box(deref(deref(v.this.#^inherit_outer.eimer.map.v).#^inherit_outer.eimer.map).v)'
To solve this, you could change the type of the target 'a' to 'inherit_outer.eimer.T' or convert the type of the assigned value to 'inherit_outer.eimer.map.B'.

one error.

It works when adding ref

inherit_outer is

  eimer(T type) ref is

    v T is abstract

    map(B type, f T -> B) : eimer B is
      v B is f eimer.this.v

  bucket(U type, v U) : eimer U is

  hellos => bucket "hello"
  fives => hellos.map s->s.byte_length

  say hellos.v
  say fives.v
 > ../../work/build/bin/fz inherit_outer.fz
hello
5

fridis avatar Mar 10 '23 21:03 fridis

updated syntax:

inherit_outer is

  eimer(T type) is

    v T => abstract

    map(B type, f T -> B) : eimer B is
      val B => f eimer.this.v

  bucket(U type, redef v U) : eimer U is

  hellos => bucket "hello"
  fives => hellos.map s->s.byte_length

  say hellos.v
  say fives.v

michaellilltokiwa avatar Jul 16 '24 07:07 michaellilltokiwa

smaller example

inherit_outer is
  eimer(T type) is
    v T => abstract
    map(B type, f T->B) B : eimer B =>
      f eimer.this.v

michaellilltokiwa avatar Feb 19 '25 12:02 michaellilltokiwa