From 23afe3c9b9ff6f1c9d31cea678909003ca8f943b Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Thu, 10 May 2012 13:48:32 +0200 Subject: Fix for SI-5654. More details as code comment and in the bug database. --- test/files/pos/t5654.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/files/pos/t5654.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t5654.scala b/test/files/pos/t5654.scala new file mode 100644 index 0000000000..1f8d05bfed --- /dev/null +++ b/test/files/pos/t5654.scala @@ -0,0 +1,13 @@ +class T(val a: Array[_]) + +class U { + val a = Array(Array(1, 2), Array("a","b")) +} + +class T1 { val a: Array[_] = Array(1) } + +case class Bomb(a: Array[_]) +case class Bomb2(a: Array[T] forSome { type T }) +class Okay1(a: Array[_]) +case class Okay2(s: Seq[_]) + -- cgit v1.2.3 From 4c04213b991596aa73dec3aa34cb8816a277f538 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 5 May 2012 01:23:45 -0700 Subject: Test cases. Closes SI-4482, SI-4651, SI-3702. Pending tests for SI-1832, SI-3439, SI-5091, SI-5231, SI-5265. --- test/files/pos/t4651.scala | 12 ++++++++++++ test/files/run/t3702.check | 2 ++ test/files/run/t3702.scala | 11 +++++++++++ test/files/run/t4482.check | 1 + test/files/run/t4482.scala | 15 +++++++++++++++ test/pending/pos/t1832.scala | 10 ++++++++++ test/pending/pos/t3439.scala | 2 ++ test/pending/pos/t5091.scala | 11 +++++++++++ test/pending/pos/t5231.scala | 18 ++++++++++++++++++ test/pending/pos/t5265.scala | 21 +++++++++++++++++++++ 10 files changed, 103 insertions(+) create mode 100644 test/files/pos/t4651.scala create mode 100644 test/files/run/t3702.check create mode 100644 test/files/run/t3702.scala create mode 100644 test/files/run/t4482.check create mode 100644 test/files/run/t4482.scala create mode 100644 test/pending/pos/t1832.scala create mode 100644 test/pending/pos/t3439.scala create mode 100644 test/pending/pos/t5091.scala create mode 100644 test/pending/pos/t5231.scala create mode 100644 test/pending/pos/t5265.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t4651.scala b/test/files/pos/t4651.scala new file mode 100644 index 0000000000..0612a8fcfb --- /dev/null +++ b/test/files/pos/t4651.scala @@ -0,0 +1,12 @@ +object Test { + def analyze(x: Any) = x match { + case s: String => println("It's a string: " + s) + case 1 => println("It's a one") + case (a: Int, b) => println("It's a pair of and int " + a + + " and something " + b) + case 1 :: 2 :: _ => println("It's a list starting with 1, 2") + case List(a, b, c) => println("It's a three-element list with " + + a + ", " + b + ", " + c) + case _ => println("It's something different") + } +} diff --git a/test/files/run/t3702.check b/test/files/run/t3702.check new file mode 100644 index 0000000000..31c2ac4ed1 --- /dev/null +++ b/test/files/run/t3702.check @@ -0,0 +1,2 @@ +() +6 diff --git a/test/files/run/t3702.scala b/test/files/run/t3702.scala new file mode 100644 index 0000000000..021abcb625 --- /dev/null +++ b/test/files/run/t3702.scala @@ -0,0 +1,11 @@ +object Test { + def foo(h: Any, t: List[Any]) = h match { + case 5 :: _ => () + case List(from) => from + } + + def main(args: Array[String]): Unit = { + println(foo(5 :: Nil, List(1,2,3))) + println(foo(6 :: Nil, List(1,2,3))) + } +} diff --git a/test/files/run/t4482.check b/test/files/run/t4482.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/files/run/t4482.check @@ -0,0 +1 @@ +2 diff --git a/test/files/run/t4482.scala b/test/files/run/t4482.scala new file mode 100644 index 0000000000..392861c22e --- /dev/null +++ b/test/files/run/t4482.scala @@ -0,0 +1,15 @@ +trait Foo { def i: Int } +trait Bar + +case class Spam(i: Int) extends Foo with Bar + +object Test { + def matchParent(p:Any) = p match { + case f:Foo if f.i == 1 => 1 + case _:Bar => 2 + case _:Foo => 3 + } + def main(args: Array[String]): Unit = { + println(matchParent(Spam(3))) + } +} diff --git a/test/pending/pos/t1832.scala b/test/pending/pos/t1832.scala new file mode 100644 index 0000000000..bca863f4bd --- /dev/null +++ b/test/pending/pos/t1832.scala @@ -0,0 +1,10 @@ +// Edit by paulp: reduced. +trait Cloning { + trait Foo + def fn(g: Int => Unit): Foo + + implicit def mkStar(i: Int) = new { def *(a: Foo): Foo = null } + + val pool1 = 4 * fn { case i => i * 2 } + val pool2 = 4 * fn { case i: Int => i * 2 } +} diff --git a/test/pending/pos/t3439.scala b/test/pending/pos/t3439.scala new file mode 100644 index 0000000000..425f1aeeb5 --- /dev/null +++ b/test/pending/pos/t3439.scala @@ -0,0 +1,2 @@ +abstract class ParametricMessage[M: Manifest](msg: M) { def message = msg } +case class ParametricMessage1[M: Manifest](msg: M, p1: Class[_]) extends ParametricMessage(msg) diff --git a/test/pending/pos/t5091.scala b/test/pending/pos/t5091.scala new file mode 100644 index 0000000000..217e83f66d --- /dev/null +++ b/test/pending/pos/t5091.scala @@ -0,0 +1,11 @@ +object RecursiveValueNeedsType { + + def foo(param: String) = 42 + def bar(n: Int) = 42 + + { + val xxx = foo(param = null) + val param = bar(xxx) + } + +} diff --git a/test/pending/pos/t5231.scala b/test/pending/pos/t5231.scala new file mode 100644 index 0000000000..77e6631ebb --- /dev/null +++ b/test/pending/pos/t5231.scala @@ -0,0 +1,18 @@ +object Client { + sealed trait ConfigLike { + def clientID: Int + } + + object Config { + def apply() : ConfigBuilder = new ConfigBuilder() + implicit def build( cb: ConfigBuilder ) : Config = cb.build + } + + final class Config private[Client]( val clientID: Int ) + extends ConfigLike + + final class ConfigBuilder private () extends ConfigLike { + var clientID: Int = 0 + def build : Config = new Config( clientID ) + } +} diff --git a/test/pending/pos/t5265.scala b/test/pending/pos/t5265.scala new file mode 100644 index 0000000000..3be7d2187e --- /dev/null +++ b/test/pending/pos/t5265.scala @@ -0,0 +1,21 @@ +import java.util.Date + +trait TDate + +trait TT[A1,T1] + +trait TTFactory[F,G] { + def create(f: F) : TT[F,G] + def sample: F +} + +object Impls { + + // If the c1 is declared before c2, it compiles fine + implicit def c2(s: Date) = c1.create(s) + + implicit val c1 = new TTFactory[Date,TDate] { + def create(v: Date): TT[Date,TDate] = sys.error("") + def sample = new Date + } +} \ No newline at end of file -- cgit v1.2.3 From e40f3c8790bfa630d0a3e554251f7ada790116da Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 11 May 2012 07:44:12 +0200 Subject: Test case closes SI-2435. --- test/files/pos/t2435.scala | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/files/pos/t2435.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t2435.scala b/test/files/pos/t2435.scala new file mode 100644 index 0000000000..2db931b99f --- /dev/null +++ b/test/files/pos/t2435.scala @@ -0,0 +1,27 @@ +object Bug { + abstract class FChain { + type T + + def chain(constant:String) = + new FConstant[this.type](constant, this) //removing [this.type], everything compiles + } + + case class FConstant[E <: FChain](constant:String, tail:E) extends FChain { + type T = tail.T + } + + object FNil extends FChain { + type T = Unit + } + +} + +object Test { + import Bug._ + println("Compiles:") + val a1 = FNil.chain("a").chain("a") + val a2 = a1.chain("a") + + println("\nDoesn't compile:") + val a = FNil.chain("a").chain("a").chain("a") +} -- cgit v1.2.3 From ef32a8b9334307d15d9fa68d3da3f6f80b200788 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 10 May 2012 23:19:55 -0700 Subject: Removing redunant/passing tests from pending. --- test/files/pos/t1987.scala | 8 -------- test/files/pos/t1987a.scala | 8 ++++++++ test/files/run/backreferences.check | 2 ++ test/files/run/backreferences.scala | 13 +++++++++++++ test/pending/neg/t796.scala | 20 -------------------- test/pending/pos/unapplyGeneric.scala | 11 ----------- test/pending/run/t3702.scala | 10 ---------- test/pending/run/t5629.scala | 25 ------------------------- 8 files changed, 23 insertions(+), 74 deletions(-) delete mode 100644 test/files/pos/t1987.scala create mode 100644 test/files/pos/t1987a.scala create mode 100644 test/files/run/backreferences.check create mode 100644 test/files/run/backreferences.scala delete mode 100644 test/pending/neg/t796.scala delete mode 100644 test/pending/pos/unapplyGeneric.scala delete mode 100644 test/pending/run/t3702.scala delete mode 100644 test/pending/run/t5629.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t1987.scala b/test/files/pos/t1987.scala deleted file mode 100644 index ccab133716..0000000000 --- a/test/files/pos/t1987.scala +++ /dev/null @@ -1,8 +0,0 @@ -package object overloading { - def bar(f: (Int) => Unit): Unit = () - def bar(f: (Int, Int) => Unit): Unit = () -} - -class PackageObjectOverloadingTest { - overloading.bar( (i: Int) => () ) // doesn't compile. -} diff --git a/test/files/pos/t1987a.scala b/test/files/pos/t1987a.scala new file mode 100644 index 0000000000..ccab133716 --- /dev/null +++ b/test/files/pos/t1987a.scala @@ -0,0 +1,8 @@ +package object overloading { + def bar(f: (Int) => Unit): Unit = () + def bar(f: (Int, Int) => Unit): Unit = () +} + +class PackageObjectOverloadingTest { + overloading.bar( (i: Int) => () ) // doesn't compile. +} diff --git a/test/files/run/backreferences.check b/test/files/run/backreferences.check new file mode 100644 index 0000000000..1d474d5255 --- /dev/null +++ b/test/files/run/backreferences.check @@ -0,0 +1,2 @@ +false +true diff --git a/test/files/run/backreferences.scala b/test/files/run/backreferences.scala new file mode 100644 index 0000000000..335cd6c7de --- /dev/null +++ b/test/files/run/backreferences.scala @@ -0,0 +1,13 @@ +case class Elem[T](x: T, y: T) + +object Test { + def unrolled[T](x: Any, y: Any, z: Any) = (x, y, z) match { + case (el: Elem[_], el.x, el.y) => true + case _ => false + } + + def main(args: Array[String]): Unit = { + println(unrolled(Elem("bippy", 5), "bippy", 6)) + println(unrolled(Elem("bippy", 5), "bippy", 5)) + } +} diff --git a/test/pending/neg/t796.scala b/test/pending/neg/t796.scala deleted file mode 100644 index c013f49686..0000000000 --- a/test/pending/neg/t796.scala +++ /dev/null @@ -1,20 +0,0 @@ -case class CaseClass( value: Int ); - -object PatternMatchBug { - def matcher( a: AnyRef, b: Any ) { - (a, b) match { - case ( instance: CaseClass, instance.value ) => - System.out.println( "Match succeeded!" ); - case _ => - System.out.println( "Match failed!" ); - } - } - - def main( args : Array[String] ) { - val caseClassInstance = CaseClass( 42 ) - - matcher( caseClassInstance, 13 ) - matcher( caseClassInstance, 42 ) - } -} - diff --git a/test/pending/pos/unapplyGeneric.scala b/test/pending/pos/unapplyGeneric.scala deleted file mode 100644 index bf88816885..0000000000 --- a/test/pending/pos/unapplyGeneric.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Bar { - def unapply[A,B](bar:Bar[A,B]) = Some(bar) -} - -class Bar[A,B](val _1:A, val _2:B) extends Product2[A,B] - -object Test { - new Bar(2, 'a') match { - case Bar(x,y) => - } -} diff --git a/test/pending/run/t3702.scala b/test/pending/run/t3702.scala deleted file mode 100644 index e08fc12e76..0000000000 --- a/test/pending/run/t3702.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Test { - def main(args: Array[String]) { - foo(Nil, Nil) - } - - def foo(h: Any, t: List[Any]) = h match { - case 5 :: _ => () - case List(from) => List(from, from, from) - } -} diff --git a/test/pending/run/t5629.scala b/test/pending/run/t5629.scala deleted file mode 100644 index 28e74a1c94..0000000000 --- a/test/pending/run/t5629.scala +++ /dev/null @@ -1,25 +0,0 @@ -import scala.{specialized => spec} - -trait GrandParent[@spec(Int) -A] { - def foo(a:A): Unit - def bar[B <: A](b:B): Unit = println("grandparent got: %s" format b) -} - -trait Parent[@spec(Int) -A] extends GrandParent[A] { - def foo(a:A) = bar(a) -} - -class IntChild extends Parent[Int] { - override def bar[B <: Int](b:B): Unit = println("int child got: %s" format b) -} - -class AnyChild extends Parent[Any] { - override def bar[B <: Any](b:B): Unit = println("any child got: %s" format b) -} - -object Test { - def main(args:Array[String]) { - new IntChild().foo(33) - new AnyChild().foo(33) - } -} -- cgit v1.2.3 From 82f3e49b37043e9f7661a43fe28c158dec4a3f31 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 9 May 2012 19:10:37 +0200 Subject: fixes a problem with an extractor object overloaded by a regular def --- src/compiler/scala/reflect/internal/Types.scala | 4 +++ .../scala/tools/nsc/typechecker/Typers.scala | 7 ++++- .../pos/overloaded_extractor_and_regular_def.scala | 32 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/overloaded_extractor_and_regular_def.scala (limited to 'test/files/pos') diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 09e7303b90..81582db5f2 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -2663,6 +2663,10 @@ trait Types extends api.Types { self: SymbolTable => override def kind = "OverloadedType" } + def overloadedType(pre: Type, alternatives: List[Symbol]): Type = + if (alternatives.tail.isEmpty) pre memberType alternatives.head + else OverloadedType(pre, alternatives) + /** A class remembering a type instantiation for some a set of overloaded * polymorphic symbols. * Not used after phase `typer`. diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 34e1aaedfd..b5e58efaff 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -958,9 +958,14 @@ trait Typers extends Modes with Adaptations with Taggings { * see test/files/../t5189*.scala */ def adaptConstrPattern(): Tree = { // (5) - val extractor = tree.symbol.filter(sym => reallyExists(unapplyMember(sym.tpe))) + def isExtractor(sym: Symbol) = reallyExists(unapplyMember(sym.tpe)) + val extractor = tree.symbol filter isExtractor if (extractor != NoSymbol) { tree setSymbol extractor + tree.tpe match { + case OverloadedType(pre, alts) => tree.tpe = overloadedType(pre, alts filter isExtractor) + case _ => + } val unapply = unapplyMember(extractor.tpe) val clazz = unapplyParameterType(unapply) diff --git a/test/files/pos/overloaded_extractor_and_regular_def.scala b/test/files/pos/overloaded_extractor_and_regular_def.scala new file mode 100644 index 0000000000..c8e7da5cad --- /dev/null +++ b/test/files/pos/overloaded_extractor_and_regular_def.scala @@ -0,0 +1,32 @@ +trait TreesBase { + type Tree + + type Apply <: Tree + + val Apply: ApplyExtractor + + abstract class ApplyExtractor { + def apply(x: Int): Apply + def unapply(apply: Apply): Option[Int] + } +} + +trait TreesApi extends TreesBase { + def Apply(x: String) +} + +class Universe extends TreesApi { + abstract class Tree + case class Apply(x: Int) extends Tree + object Apply extends ApplyExtractor + def Apply(x: String) = Apply(x.toInt) +} + +object Test extends App { + def foo(tapi: TreesApi) { + import tapi._ + def bar(tree: Tree) { + val Apply(x) = tree + } + } +} \ No newline at end of file -- cgit v1.2.3 From 807567230852bcadb98a91322bd348aae764801f Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 11 May 2012 10:25:34 -0700 Subject: Recognize java enums as constants from source. Fixed up one of the mismatches between how java source is modeled and how java bytecode is modeled. We should get the rest of them too. Closes SI-2764. --- src/compiler/scala/reflect/internal/StdNames.scala | 1 - src/compiler/scala/tools/nsc/javac/JavaParsers.scala | 5 ++++- src/compiler/scala/tools/nsc/typechecker/Namers.scala | 8 ++++++++ test/files/pos/t2764/Ann.java | 5 +++++ test/files/pos/t2764/Enum.java | 5 +++++ test/files/pos/t2764/Use.scala | 6 ++++++ 6 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/files/pos/t2764/Ann.java create mode 100644 test/files/pos/t2764/Enum.java create mode 100644 test/files/pos/t2764/Use.scala (limited to 'test/files/pos') diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala index 0cdf65bd8f..bd4d9a9f34 100644 --- a/src/compiler/scala/reflect/internal/StdNames.scala +++ b/src/compiler/scala/reflect/internal/StdNames.scala @@ -766,7 +766,6 @@ trait StdNames { object fulltpnme extends TypeNames { val RuntimeNothing: NameType = "scala.runtime.Nothing$" val RuntimeNull: NameType = "scala.runtime.Null$" - val JavaLangEnum: NameType = "java.lang.Enum" } /** Java binary names, like scala/runtime/Nothing$. diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 5c413243e8..f71e067366 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -872,7 +872,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { skipAhead() accept(RBRACE) } - ValDef(Modifiers(Flags.JAVA | Flags.STATIC), name, enumType, blankExpr) + // The STABLE flag is to signal to namer that this was read from a + // java enum, and so should be given a Constant type (thereby making + // it usable in annotations.) + ValDef(Modifiers(Flags.STABLE | Flags.JAVA | Flags.STATIC), name, enumType, blankExpr) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index ca4b1d3de8..e4b744dffc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -567,7 +567,15 @@ trait Namers extends MethodSynthesis { assignAndEnterFinishedSymbol(tree) else enterGetterSetter(tree) + + // When java enums are read from bytecode, they are known to have + // constant types by the jvm flag and assigned accordingly. When + // they are read from source, the java parser marks them with the + // STABLE flag, and now we receive that signal. + if (tree.symbol hasAllFlags STABLE | JAVA) + tree.symbol setInfo ConstantType(Constant(tree.symbol)) } + def enterLazyVal(tree: ValDef, lazyAccessor: Symbol): TermSymbol = { // If the owner is not a class, this is a lazy val from a method, // with no associated field. It has an accessor with $lzy appended to its name and diff --git a/test/files/pos/t2764/Ann.java b/test/files/pos/t2764/Ann.java new file mode 100644 index 0000000000..184fc6e864 --- /dev/null +++ b/test/files/pos/t2764/Ann.java @@ -0,0 +1,5 @@ +package bippy; + +public @interface Ann { + Enum value(); +} diff --git a/test/files/pos/t2764/Enum.java b/test/files/pos/t2764/Enum.java new file mode 100644 index 0000000000..fe07559535 --- /dev/null +++ b/test/files/pos/t2764/Enum.java @@ -0,0 +1,5 @@ +package bippy; + +public enum Enum { + VALUE; +} diff --git a/test/files/pos/t2764/Use.scala b/test/files/pos/t2764/Use.scala new file mode 100644 index 0000000000..8cf8102709 --- /dev/null +++ b/test/files/pos/t2764/Use.scala @@ -0,0 +1,6 @@ +package bippy + +class Use { + @Ann(Enum.VALUE) + def foo {} +} -- cgit v1.2.3 From 3511e5960d510eafcb67c388ec0b5b60aafdd8f3 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 11 May 2012 11:06:55 -0700 Subject: Test case closes SI-5165. Also fixed by annotation/enum commit. --- test/files/pos/t5165/TestAnnotation.java | 11 +++++++++++ test/files/pos/t5165/TestObject.scala | 3 +++ test/files/pos/t5165/TestTrait.scala | 3 +++ 3 files changed, 17 insertions(+) create mode 100644 test/files/pos/t5165/TestAnnotation.java create mode 100644 test/files/pos/t5165/TestObject.scala create mode 100644 test/files/pos/t5165/TestTrait.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t5165/TestAnnotation.java b/test/files/pos/t5165/TestAnnotation.java new file mode 100644 index 0000000000..90886b7537 --- /dev/null +++ b/test/files/pos/t5165/TestAnnotation.java @@ -0,0 +1,11 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface TestAnnotation { + public enum TestEnumOne { A, B } + public enum TestEnumTwo { C, D } + + public TestEnumOne one(); + public TestEnumTwo two(); + public String strVal(); +} diff --git a/test/files/pos/t5165/TestObject.scala b/test/files/pos/t5165/TestObject.scala new file mode 100644 index 0000000000..eaf244e9d0 --- /dev/null +++ b/test/files/pos/t5165/TestObject.scala @@ -0,0 +1,3 @@ + +object TestObject extends TestTrait + diff --git a/test/files/pos/t5165/TestTrait.scala b/test/files/pos/t5165/TestTrait.scala new file mode 100644 index 0000000000..b317e6c6a3 --- /dev/null +++ b/test/files/pos/t5165/TestTrait.scala @@ -0,0 +1,3 @@ + +@TestAnnotation(one=TestAnnotation.TestEnumOne.A, two=TestAnnotation.TestEnumTwo.C, strVal="something") +trait TestTrait -- cgit v1.2.3