From 91eff8e6d903a9eab2bc83c120774d623df5ad7d Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 12 Nov 2010 00:07:37 +0000 Subject: Half of an implementation of sealedness for jav... Half of an implementation of sealedness for java enums. Since it's only half it's behind -Xexperimental, but it works like a charm for the half where it works (that being compiling against bytecode.) Need input on how to approach the source half. References ticket #2442. Review by moors. --- src/compiler/scala/tools/nsc/Global.scala | 1 + .../nsc/symtab/classfile/ClassfileParser.scala | 24 +++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index c2136edbb6..0f05a7fcce 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -222,6 +222,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable def debug = settings.debug.value def deprecation = settings.deprecation.value + def experimental = settings.Xexperimental.value def fatalWarnings = settings.Xwarnfatal.value def logClasspath = settings.Ylogcp.value def printLate = settings.printLate.value diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 2c47239a92..a051177a87 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -603,14 +603,28 @@ abstract class ClassfileParser { if ((sflags & PRIVATE) != 0L && !global.settings.XO.value) { in.skip(4); skipAttributes() } else { - val name = pool.getName(in.nextChar) - val info = pool.getType(in.nextChar) - val sym = getOwner(jflags) - .newValue(NoPosition, name).setFlag(sflags) - sym.setInfo(if ((jflags & JAVA_ACC_ENUM) == 0) info else ConstantType(Constant(sym))) + val name = pool.getName(in.nextChar) + val info = pool.getType(in.nextChar) + val sym = getOwner(jflags).newValue(NoPosition, name).setFlag(sflags) + val isEnum = (jflags & JAVA_ACC_ENUM) != 0 + + sym setInfo { + if (isEnum) ConstantType(Constant(sym)) + else info + } setPrivateWithin(sym, jflags) parseAttributes(sym, info) getScope(jflags).enter(sym) + + // sealed java enums (experimental) + if (isEnum && opt.experimental) { + // need to give singleton type + sym setInfo info.narrow + if (!sym.superClass.isSealed) + sym.superClass setFlag (SEALED | ABSTRACT) + + sym.superClass addChild sym + } } } -- cgit v1.2.3