Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong usage of choice type causes severe bug: "Found error clazz in set of clazzes in the IR even though no earlier errors were reported." #3362

Closed
simonvonhackewitz opened this issue Jul 11, 2024 · 1 comment
Assignees
Labels
bug Something isn't working front end related to the front end until .fum file is created: call and type resolution, type checking, etc.

Comments

@simonvonhackewitz
Copy link
Contributor

The error message is

error 1: Found error clazz in set of clazzes in the IR even though no earlier errors were reported.  This can only be the result of a severe bug.

one error.

The code causing the error

base32_test is
  my_c : choice String (array u8) is
  mk_choice(x my_c) => x

  # RFC 4618 test vectors
  base32_test_vectors array (tuple my_c String) :=
    [(mk_choice "fo", "MZXQ===="),
     (mk_choice "foo", "MZXW6===")]

  dummy_decode(arr array u8) outcome (array u8) => [0,0,0]

  dec_test =>
    for tup in base32_test_vectors do
      (plain_expected, code) := tup
      out :=
        match dummy_decode code.utf8.as_array
          arr array u8 =>
            plain_actual := String.type.from_bytes arr
            if plain_actual != plain_expected
              error "decoding $code produced '$plain_actual' but should have been '$plain_expected'"
            else
              outcome "ok"
          e error => error "error in test data"
    until !out.ok
      out.err.as_string
    else
      "RFC 4648 test vectors are decoded correctly"
  say dec_test
@michaellilltokiwa michaellilltokiwa added bug Something isn't working front end related to the front end until .fum file is created: call and type resolution, type checking, etc. labels Jul 11, 2024
@fridis
Copy link
Member

fridis commented Jul 15, 2024

Reduced the example to reproduce this:

c : choice i32 unit is
a c := 0
_ := 0 != a

with checks, this gives

 > PRECONDITIONS=true POSTCONDITIONS=true ./build/bin/fz ex3362.fz 

error 1: java.lang.Error: ensure-condition failed: AbstractFeature.java:1498 "(this == Types.f_ERROR || ancestor == Types.f_ERROR || Errors.any() || result != null);"
	at dev.flang.util.ANY.ensure(ANY.java:292)
	at dev.flang.ast.AbstractFeature.findInheritanceChain(AbstractFeature.java:1498)
	at dev.flang.air.Clazz.findRedefinition(Clazz.java:1011)
	at dev.flang.air.Clazz.lookup(Clazz.java:1212)
	at dev.flang.air.Clazzes.findClazzes(Clazzes.java:758)
	at dev.flang.air.Clazz$EV.action(Clazz.java:169)
	at dev.flang.ast.Expr.visitExpressions(Expr.java:338)
	at dev.flang.ast.AbstractCall.visitExpressions(AbstractCall.java:99)
	at dev.flang.ast.AbstractAssign.visitExpressions(AbstractAssign.java:139)
	at dev.flang.ast.AbstractBlock.visitExpressions(AbstractBlock.java:99)
	at dev.flang.ast.AbstractFeature.visitExpressions(AbstractFeature.java:1594)
	at dev.flang.air.Clazz.inspectCode(Clazz.java:1528)
	at dev.flang.air.Clazz.findAllClasses(Clazz.java:1572)
	at dev.flang.air.Clazzes.findAllClasses(Clazzes.java:408)
	at dev.flang.fuir.FUIR.<init>(FUIR.java:185)
	at dev.flang.opt.Optimizer.fuir(Optimizer.java:73)
	at dev.flang.tools.Fuzion$Backend.processFrontEnd(Fuzion.java:506)
	at dev.flang.tools.Fuzion.lambda$parseArgsForBackend$3(Fuzion.java:1070)
	at dev.flang.tools.Tool.lambda$run$0(Tool.java:141)
	at dev.flang.util.Errors.runAndExit(Errors.java:957)
	at dev.flang.tools.Tool.run(Tool.java:141)
	at dev.flang.tools.Fuzion.main(Fuzion.java:626)

*** fatal errors encountered, stopping.
one error.

@fridis fridis self-assigned this Jul 15, 2024
@fridis fridis closed this as completed in e36b98e Jul 15, 2024
fridis added a commit that referenced this issue Jul 15, 2024
ast: When checking actual type par against constraints, do not walk through inh chain of choice Fix #3362
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working front end related to the front end until .fum file is created: call and type resolution, type checking, etc.
Projects
None yet
Development

No branches or pull requests

3 participants