fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

Error `Illegal forward or cyclic type inference` causes `java.lang.StackOverflowError`

Open simonvonhackewitz opened this issue 1 year ago • 0 comments

This is the faulty code

out :=
  for res := [], res ++ new_res
      i := 0, i+1
  while i<10
  do
    new_res := [i]

say out

And the error is

/home/simon/playground/java_exception_test.fz:2:7: error 1: Illegal forward or cyclic type inference
  for res := [], res ++ new_res
------^^^
The definition of a field using ':=', or of a feature or function
using '=>' must not create cyclic type dependencies.
Referenced feature: 'res' at /home/simon/playground/java_exception_test.fz:2:7:
  for res := [], res ++ new_res
------^^^


error 2: java.lang.StackOverflowError
        at dev.flang.ast.Assign.<init>(Assign.java:117)
        at dev.flang.ast.Feature$9.<init>(Feature.java:2047)
        at dev.flang.ast.Feature.resolveTypes(Feature.java:2046)
        at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1379)
        at dev.flang.ast.Feature.visit(Feature.java:2013)
        at dev.flang.ast.Impl.inferredType(Impl.java:616)
        at dev.flang.ast.Feature.resultTypeIfPresent(Feature.java:2349)
        at dev.flang.ast.AbstractAssign.resultTypeKnown(AbstractAssign.java:245)
        ...

simonvonhackewitz avatar Jul 09 '24 14:07 simonvonhackewitz