Skip to content

Java code generator casts java.lang.Integer to byte instead of using conversion method #6277

@ssomayyajula

Description

@ssomayyajula

Dafny version

4.10.1, but at least since 4.9.2

Code to produce this issue

datatype Option<A> = Some(value: A) | None()

import opened Std.BoundedInts

method M(bucket: Option<uint32>) returns (out: uint8)
  requires bucket.Some?
{
  out := bucket.value as uint8;
}

Command to run and resulting output

dafny build --no-verify --target=java --standard-libraries

error: incompatible types: Integer cannot be converted to byte
      out = ((byte) ((bucket).dtor_value()));
                    ^
1 error

What happened?

Should compile, but a workaround is to write (bucket.value as int) as uint8.

What type of operating system are you experiencing the problem on?

Mac

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-workaround: yesThere is a known workaroundkind: bugCrashes, unsoundness, incorrect output, etc. If possible, add a `part:` labellang: javaDafny's Java transpiler and its runtimepart: code-generationSupport for transpiling Dafny to another language. If relevant, add a `lang:` tag

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions