Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Enum conversions are broken #69

Closed
eallik opened this Issue · 3 comments

2 participants

@eallik

This

public class TestCls {
    enum Foo {
        BLA
    }

    public void doSmth(Foo f) {
        int i = 3; //  the switch must not be the only expression; otherwise another conversion error will happen to (see issue #9)
        switch (f) {
        case BLA:
            return;
        }
    }
}

is converted to:

import TestCls._

object TestCls {
  object Foo extends Enumeration {
    val BLA = new Foo()
    class Foo extends Val
    implicit def convertValue(v: Value): Foo = v.asInstanceOf[Foo]
  }
}

class TestCls {
  def doSmth(f: Foo) {
    val i = 3
    f match {
      case BLA => return // not found: value BLA
    }
  }
}

...case BLA should actually be Foo.BLA, or there needs to be a import Foo._.

P.S. the issue might stem from the fact that in Java, in normal expressions/statements, enum values need to be prefixed with the name of the enum (Foo.BLA) but in switch-case blocks, the opposite is true; now Scalagen probably just assumes a direct conversion is always correct, whereas it's not.

@eallik eallik referenced this issue in dnadolny/java-to-scala-plugin
Closed

Enum conversions are broken #10

@timowest

I am not sure if this can be fixed, since we don't really know what the type is. The example is very simple, but in Java you can match enum literals without having the enum type imported.

@eallik

Wouldn't it be possible to determine which enum an unimported literal is pointing to and just do the appropriate import in Scala?

@timowest

Closing, since scalagen operates on the source level and no type information is available. Feel free to reopen if you have a concrete idea for a fix.

@timowest timowest closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.