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

Compiler error with if for enum data definition #296

Closed
praalhans opened this Issue Aug 3, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@praalhans
Copy link

praalhans commented Aug 3, 2016

Given the following minimal example:

module bug.Example3 where

data RType = DeadEnd | WinningCycle | LosingCycle

exampleGood :: (RType, ())
exampleGood = (l w', ()) where
  l true = WinningCycle
  l false = LosingCycle
  w' = if true then false else true

exampleBad :: (RType, ())
exampleBad = (if w' then WinningCycle else LosingCycle, ()) where
  w' = if true then false else true

Observe that exampleGood and exampleBad have the same type signature and behaviour. The first example compiles fine. The last example introduces the following compiler error in Java:

Multiple messages at this line.
    -Type mismatch: cannot convert from Object&Serializable&Comparable<?> to Short
    -Java compiler errors are almost always caused by bad native declarations. When you're sure this is out of the question you've found a compiler bug, please 
     report under https://github.com/frege/frege/issues and attach a copy of

Clearly the problem is with the compiler, since it emits something similar to:

package bug;

public class Example {

    final public static class TRType  {
      final public static short WinningCycle = 1;
      final public static short DeadEnd = 0;
      final public static short LosingCycle = 2;
    }

    public Short call() {
        return true ? false : true ? TRType.WinningCycle : TRType.LosingCycle;
    }

}

A correct compiler would introduce the parenthesis, i.e.:

return (true ? false : true) ? TRType.WinningCycle : TRType.LosingCycle;

But without parenthesis, Java sees the compiled statement as a right-associative statement, which is incorrectly typed:

return true ? false : (true ? TRType.WinningCycle : TRType.LosingCycle);

@Ingo60 Ingo60 closed this in a3f3864 Aug 19, 2016

Ingo60 added a commit that referenced this issue Aug 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.