tokiwa-software / fuzion

The Fuzion Language Implementation
https://fuzion-lang.dev
GNU General Public License v3.0
46 stars 11 forks source link

Confusing type inference error message #929

Open fridis opened 1 year ago

fridis commented 1 year ago

This example results in an error referencing the call at line 8, which is not part of the cycle

 > cat fib_zip_strange_cyclic_error.fz 
fib_zip is

  list(A type, h A, t ()->list A) list A is nil

  infix : (A type, val A, l ()->list A) => list val l

  fibs => ()->(0 : ()->fibs.zip 1:()->fibs a,b->a+b)
  fib(n i32) => (fibs().drop n).head
 > ./build/bin/fz fib_zip_strange_cyclic_error.fz 

/home/fridi/fuzion/work/fib_zip_strange_cyclic_error.fz:8:18: error 1: Illegal forward or cyclic type inference
  fib(n i32) => (fibs().drop n).head
-----------------^
The definition of a field using ':=', or of a feature or function
using '=>' must not create cyclic type dependencies.
Referenced feature: 'fib_zip.fibs' at /home/fridi/fuzion/work/fib_zip_strange_cyclic_error.fz:7:3:
  fibs => ()->(0 : ()->fibs.zip 1:()->fibs a,b->a+b)
--^

one error.
fridis commented 1 year ago

updated the example to work with current Fuzion:

fib_zip is

  listX(A type, h A, t ()->list A) list A is nil

  infix :: (A type, val A, l ()->list A) => listX val l

  fibs => ()->(0 :: ()->fibs.zip 1:()->fibs a,b->a+b)
  fib(n i32) => (fibs().drop n).head

results in

 > ./build/bin/fz ex_929.fz 

/home/fridi/fuzion/work/ex_929.fz:9:18: error 1: Illegal forward or cyclic type inference
  fib(n i32) => (fibs().drop n).head
-----------------^
The definition of a field using ':=', or of a feature or function
using '=>' must not create cyclic type dependencies.
Referenced feature: 'fib_zip.fibs' at /home/fridi/fuzion/work/ex_929.fz:8:3:
  fibs => ()->(0 :: ()->fibs.zip 1:()->fibs a,b->a+b)
--^

one error.
michaellilltokiwa commented 4 months ago

I think one possible reason this may happen is because fields types are inferred via outer. If outer is not inferred yet field can not be inferred leading to this error.