Skip to content

Commit 44807a7

Browse files
committed
SI-6613 Make Java enums work in FSC / REPL
We needed to hop from the enum's owner to its companion module in an early phase of the compiler. The enclosed test used to fail when this lookup returned NoSymbol on the second run of the resident compiler when triggered from `MixinTransformer`: the lookup didn't work after the flatten info transform. This is related to the fact that module classes are flattened into the enclosing package, but module accessors remain in the enclosing class.
1 parent 9a87034 commit 44807a7

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

src/reflect/scala/reflect/internal/Definitions.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,14 @@ trait Definitions extends api.StandardDefinitions {
904904
)
905905
}
906906

907-
def EnumType(sym: Symbol) =
907+
def EnumType(sym: Symbol) = {
908908
// given (in java): "class A { enum E { VAL1 } }"
909909
// - sym: the symbol of the actual enumeration value (VAL1)
910910
// - .owner: the ModuleClassSymbol of the enumeration (object E)
911911
// - .linkedClassOfClass: the ClassSymbol of the enumeration (class E)
912-
sym.owner.linkedClassOfClass.tpe
912+
// SI-6613 Subsequent runs of the resident compiler demand the phase discipline here.
913+
enteringPhaseNotLaterThan(picklerPhase)(sym.owner.linkedClassOfClass).tpe
914+
}
913915

914916
/** Given a class symbol C with type parameters T1, T2, ... Tn
915917
* which have upper/lower bounds LB1/UB1, LB1/UB2, ..., LBn/UBn,

test/files/res/t6613.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
nsc>
3+
nsc>
4+
nsc>
5+
nsc>

test/files/res/t6613.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
t6613/Enummy.java
2+
t6613/Broken.scala
3+
t6613/Broken.scala

test/files/res/t6613/Broken.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Broken() { def broken() = Enummy.Broke.CHIP }

test/files/res/t6613/Enummy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public class Enummy { public enum Broke { SHARD, CHIP } }

0 commit comments

Comments
 (0)