From 453d615fb3c6d0db3a0a43c9232bc12584e39107 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 3 May 2012 11:30:33 -0700 Subject: Fix for SI-5608, crasher with value classes. Anyone who doubts the importance of avoiding duplication is invited to look closely at the cause of this bug as revealed in this one line patch. --- src/compiler/scala/reflect/internal/Types.scala | 4 +++- src/compiler/scala/tools/nsc/ast/Trees.scala | 2 +- test/files/run/t5608.check | 1 + test/files/run/t5608.scala | 12 ++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/files/run/t5608.check create mode 100644 test/files/run/t5608.scala diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 799671f9e3..9867c23c70 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -3276,8 +3276,10 @@ trait Types extends api.Types { self: SymbolTable => final class UniqueErasedValueType(sym: Symbol) extends ErasedValueType(sym) with UniqueType object ErasedValueType { - def apply(sym: Symbol): Type = + def apply(sym: Symbol): Type = { + assert(sym ne NoSymbol, "ErasedValueType cannot be NoSymbol") unique(new UniqueErasedValueType(sym)) + } } /** A class representing an as-yet unevaluated type. diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index a355db4d9a..4c509778e9 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -195,7 +195,7 @@ trait Trees extends reflect.internal.Trees { self: Global => def SelectFromArray(tree: Tree, qualifier: Tree, selector: Name, erasure: Type) = new SelectFromArray(qualifier, selector, erasure).copyAttrs(tree) def InjectDerivedValue(tree: Tree, arg: Tree) = - new InjectDerivedValue(arg) + new InjectDerivedValue(arg).copyAttrs(tree) def TypeTreeWithDeferredRefCheck(tree: Tree) = tree match { case dc@TypeTreeWithDeferredRefCheck() => new TypeTreeWithDeferredRefCheck()(dc.check).copyAttrs(tree) } diff --git a/test/files/run/t5608.check b/test/files/run/t5608.check new file mode 100644 index 0000000000..ba70d21701 --- /dev/null +++ b/test/files/run/t5608.check @@ -0,0 +1 @@ +A@6 diff --git a/test/files/run/t5608.scala b/test/files/run/t5608.scala new file mode 100644 index 0000000000..19b3681932 --- /dev/null +++ b/test/files/run/t5608.scala @@ -0,0 +1,12 @@ +object Test { + def main(args:Array[String]) { + val ns = Array(3L, 3L, 3L) + val a1: A = new A(ns(0)) + val a2: A = new A(ns(0)) + println(a1 + a2) + } +} + +class A(val u: Long) extends AnyVal { + def +(other: A) = new A(other.u + u) +} -- cgit v1.2.3