diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Definitions.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Constructors.scala | 16 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 3 |
3 files changed, 20 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 63f6b90706..7afb631940 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -35,6 +35,7 @@ mixin class Definitions requires SymbolTable { var StringClass: Symbol = _; var ThrowableClass: Symbol = _; + var NullPointerExceptionClass: Symbol = _; // the scala value classes var UnitClass: Symbol = _; @@ -317,6 +318,7 @@ mixin class Definitions requires SymbolTable { StringClass = getClass("java.lang.String"); ThrowableClass = getClass("java.lang.Throwable"); + NullPointerExceptionClass = getClass("java.lang.NullPointerException"); // the scala value classes UnitClass = getValueClass("Unit", 'V'); diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index b555aa9078..1d167f78b3 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -87,6 +87,20 @@ abstract class Constructors extends Transform { } } + def copyParam(to: Symbol, from: Symbol): Tree = { + var result = mkAssign(to, Ident(from)); + if (from.name == nme.OUTER) + result = + atPos(to.pos) { + localTyper.typed { + If(Apply(Select(Ident(from), nme.eq), List(Literal(Constant(null)))), + Throw(New(TypeTree(NullPointerExceptionClass.tpe), List(List()))), + result); + } + } + result + } + val defBuf = new ListBuffer[Tree]; val constrStatBuf = new ListBuffer[Tree]; val constrPrefixBuf = new ListBuffer[Tree]; @@ -142,7 +156,7 @@ abstract class Constructors extends Transform { for (val stat <- defBuf.elements) accessTraverser.traverse(stat); val paramInits = for (val acc <- paramAccessors; isAccessed(acc)) - yield mkAssign(acc, Ident(parameter(acc))); + yield copyParam(acc, parameter(acc)) defBuf += copy.DefDef( constr, constr.mods, constr.name, constr.tparams, constr.vparamss, constr.tpt, diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1546494ed4..4472ab9def 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -761,6 +761,9 @@ mixin class Typers requires Analyzer { val lo1 = checkNoEscaping.privates(tdef.symbol, typedType(tdef.lo)) val hi1 = checkNoEscaping.privates(tdef.symbol, typedType(tdef.hi)) checkNonCyclic(tdef.symbol) + if (!(lo1.tpe <:< hi1.tpe)) + error(tdef.pos, + "lower bound "+lo1.tpe+" does not conform to upper bound "+hi1.tpe) copy.AbsTypeDef(tdef, tdef.mods, tdef.name, lo1, hi1) setType NoType } |