From 34a6fa9bb44ffd96dbb0ee59905fecf4e29879ba Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Apr 2013 17:46:16 +0300 Subject: SI-6937 core type tags are no longer referentially unique Type tag factory used to evaluate the provided type creator in the context of the initial mirror in order to maintain referential equality of instances of standard tags. Unfortunately this evaluation might fail if the mirror provided doesn't contain the classes being referred to. Therefore I think we should avoid evaluating type creators there. Note that failure of evaluation doesn't mean that there's something bad going on. When one creates a type tag, the correct mirror / classloader to interpret that tag in might be unknown (like it happens here). This is okay, and this is exactly what the 2.10.0-M4 refactoring has addressed. Something like `res2.typeTag[A].in(currentMirror)` should be okay. --- test/files/run/macro-expand-nullary-generic.check | 10 ++++----- test/files/run/macro-expand-tparams-explicit.check | 2 +- test/files/run/macro-expand-tparams-implicit.check | 2 +- test/files/run/macro-expand-tparams-prefix-a.check | 6 ++--- test/files/run/macro-expand-tparams-prefix-b.check | 4 ++-- .../files/run/macro-expand-tparams-prefix-c1.check | 4 ++-- .../files/run/macro-expand-tparams-prefix-c2.check | 4 ++-- .../files/run/macro-expand-tparams-prefix-d1.check | 2 +- test/files/run/macro-undetparams-consfromsls.check | 6 ++--- test/files/run/macro-undetparams-macroitself.check | 2 +- test/files/run/t6937.check | 26 ++++++++++++++++++++++ test/files/run/t6937.scala | 12 ++++++++++ 12 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 test/files/run/t6937.check create mode 100644 test/files/run/t6937.scala (limited to 'test/files') diff --git a/test/files/run/macro-expand-nullary-generic.check b/test/files/run/macro-expand-nullary-generic.check index 133840c469..42976f4baf 100644 --- a/test/files/run/macro-expand-nullary-generic.check +++ b/test/files/run/macro-expand-nullary-generic.check @@ -1,6 +1,6 @@ -it works TypeTag[Int] -it works TypeTag[Int] -it works TypeTag[Int] -it works TypeTag[Int] -it works TypeTag[Int] +it works WeakTypeTag[Int] +it works WeakTypeTag[Int] +it works WeakTypeTag[Int] +it works WeakTypeTag[Int] +it works WeakTypeTag[Int] kkthxbai diff --git a/test/files/run/macro-expand-tparams-explicit.check b/test/files/run/macro-expand-tparams-explicit.check index e7e6718406..b6b4f6fa3a 100644 --- a/test/files/run/macro-expand-tparams-explicit.check +++ b/test/files/run/macro-expand-tparams-explicit.check @@ -1 +1 @@ -TypeTag[Int] +WeakTypeTag[Int] diff --git a/test/files/run/macro-expand-tparams-implicit.check b/test/files/run/macro-expand-tparams-implicit.check index fa6b335afb..a9bf55423e 100644 --- a/test/files/run/macro-expand-tparams-implicit.check +++ b/test/files/run/macro-expand-tparams-implicit.check @@ -1,2 +1,2 @@ -TypeTag[Int] +WeakTypeTag[Int] WeakTypeTag[String] diff --git a/test/files/run/macro-expand-tparams-prefix-a.check b/test/files/run/macro-expand-tparams-prefix-a.check index 0bf3c55bbe..ca44a4f652 100644 --- a/test/files/run/macro-expand-tparams-prefix-a.check +++ b/test/files/run/macro-expand-tparams-prefix-a.check @@ -1,4 +1,4 @@ -TypeTag[Int] -TypeTag[Int] +WeakTypeTag[Int] +WeakTypeTag[Int] WeakTypeTag[String] -TypeTag[Boolean] +WeakTypeTag[Boolean] diff --git a/test/files/run/macro-expand-tparams-prefix-b.check b/test/files/run/macro-expand-tparams-prefix-b.check index 77c2ee9051..2ff2ce435d 100644 --- a/test/files/run/macro-expand-tparams-prefix-b.check +++ b/test/files/run/macro-expand-tparams-prefix-b.check @@ -1,2 +1,2 @@ -TypeTag[Boolean] TypeTag[Int] -TypeTag[Boolean] WeakTypeTag[String] +WeakTypeTag[Boolean] WeakTypeTag[Int] +WeakTypeTag[Boolean] WeakTypeTag[String] diff --git a/test/files/run/macro-expand-tparams-prefix-c1.check b/test/files/run/macro-expand-tparams-prefix-c1.check index f0dd5b9cd8..0f24f74db1 100644 --- a/test/files/run/macro-expand-tparams-prefix-c1.check +++ b/test/files/run/macro-expand-tparams-prefix-c1.check @@ -1,3 +1,3 @@ -TypeTag[Int] +WeakTypeTag[Int] WeakTypeTag[String] -TypeTag[Boolean] +WeakTypeTag[Boolean] diff --git a/test/files/run/macro-expand-tparams-prefix-c2.check b/test/files/run/macro-expand-tparams-prefix-c2.check index f0dd5b9cd8..0f24f74db1 100644 --- a/test/files/run/macro-expand-tparams-prefix-c2.check +++ b/test/files/run/macro-expand-tparams-prefix-c2.check @@ -1,3 +1,3 @@ -TypeTag[Int] +WeakTypeTag[Int] WeakTypeTag[String] -TypeTag[Boolean] +WeakTypeTag[Boolean] diff --git a/test/files/run/macro-expand-tparams-prefix-d1.check b/test/files/run/macro-expand-tparams-prefix-d1.check index c5aaaf5a09..7832503256 100644 --- a/test/files/run/macro-expand-tparams-prefix-d1.check +++ b/test/files/run/macro-expand-tparams-prefix-d1.check @@ -1,3 +1,3 @@ WeakTypeTag[T] WeakTypeTag[U] -TypeTag[Boolean] +WeakTypeTag[Boolean] diff --git a/test/files/run/macro-undetparams-consfromsls.check b/test/files/run/macro-undetparams-consfromsls.check index b10a90043e..3fee58d9c1 100644 --- a/test/files/run/macro-undetparams-consfromsls.check +++ b/test/files/run/macro-undetparams-consfromsls.check @@ -1,5 +1,5 @@ -A = TypeTag[Int] -B = TypeTag[Nothing] +A = WeakTypeTag[Int] +B = WeakTypeTag[Nothing] List(1) -A = TypeTag[Any] +A = WeakTypeTag[Any] List(abc, 1) diff --git a/test/files/run/macro-undetparams-macroitself.check b/test/files/run/macro-undetparams-macroitself.check index fa6b335afb..a9bf55423e 100644 --- a/test/files/run/macro-undetparams-macroitself.check +++ b/test/files/run/macro-undetparams-macroitself.check @@ -1,2 +1,2 @@ -TypeTag[Int] +WeakTypeTag[Int] WeakTypeTag[String] diff --git a/test/files/run/t6937.check b/test/files/run/t6937.check new file mode 100644 index 0000000000..9a1fa4cfaf --- /dev/null +++ b/test/files/run/t6937.check @@ -0,0 +1,26 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{universe=>ru} + +scala> import scala.reflect.runtime.{currentMirror => cm} +import scala.reflect.runtime.{currentMirror=>cm} + +scala> import scala.reflect.api.{Universe => ApiUniverse} +import scala.reflect.api.{Universe=>ApiUniverse} + +scala> class A +defined class A + +scala> lazy val apiru = ru: ApiUniverse +apiru: scala.reflect.api.Universe = + +scala> apiru.typeTag[A].in(cm) +res0: reflect.runtime.universe.TypeTag[A] = TypeTag[A] + +scala> + +scala> diff --git a/test/files/run/t6937.scala b/test/files/run/t6937.scala new file mode 100644 index 0000000000..4b30894bf3 --- /dev/null +++ b/test/files/run/t6937.scala @@ -0,0 +1,12 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ + import scala.reflect.runtime.{universe => ru} + import scala.reflect.runtime.{currentMirror => cm} + import scala.reflect.api.{Universe => ApiUniverse} + class A + lazy val apiru = ru: ApiUniverse + apiru.typeTag[A].in(cm) + """ +} \ No newline at end of file -- cgit v1.2.3 From 2885eb0b2d49c33c707cecd2ee7b9588fe3f76ab Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Mon, 8 Apr 2013 14:12:26 +0400 Subject: Revert "SI-6387 Clones accessor before name expansion" This reverts commit 4e10b2c833fa846c68b81e94a08d867e7de656aa. Add 6387 test to pending and 7341 to up-to-date. --- src/reflect/scala/reflect/internal/Symbols.scala | 35 ++++++++---------------- test/files/run/t6387.check | 1 - test/files/run/t6387.scala | 16 ----------- test/files/run/t7341.check | 0 test/files/run/t7341.flags | 1 + test/files/run/t7341.scala | 15 ++++++++++ test/pending/run/t6387.check | 1 + test/pending/run/t6387.scala | 16 +++++++++++ 8 files changed, 44 insertions(+), 41 deletions(-) delete mode 100644 test/files/run/t6387.check delete mode 100644 test/files/run/t6387.scala create mode 100644 test/files/run/t7341.check create mode 100755 test/files/run/t7341.flags create mode 100755 test/files/run/t7341.scala create mode 100644 test/pending/run/t6387.check create mode 100644 test/pending/run/t6387.scala (limited to 'test/files') diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 7274eeafe0..45c16b7302 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -2538,32 +2538,20 @@ trait Symbols extends api.Symbols { self: SymbolTable => } /** change name by appending $$ - * Do the same for any accessed symbols or setters/getters. - * If the accessor to be renamed is overriding a base symbol, enter - * a cloned symbol with the original name but without ACCESSOR flag. + * Do the same for any accessed symbols or setters/getters */ override def expandName(base: Symbol) { - def expand(sym: Symbol) { - if ((sym eq NoSymbol) || (sym hasFlag EXPANDEDNAME)) () // skip - else sym setFlag EXPANDEDNAME setName nme.expandedName(sym.name.toTermName, base) - } - def cloneAndExpand(accessor: Symbol) { - val clone = accessor.cloneSymbol(accessor.owner, (accessor.flags | ARTIFACT) & ~ACCESSOR) - expand(accessor) - log(s"Expanded overriding accessor to $accessor, but cloned $clone to preserve override") - accessor.owner.info.decls enter clone - } - def expandAccessor(accessor: Symbol) { - if (accessor.isOverridingSymbol) cloneAndExpand(accessor) else expand(accessor) - } - if (hasAccessorFlag && !isDeferred) { - expand(accessed) - } - else if (hasGetter) { - expandAccessor(getter(owner)) - expandAccessor(setter(owner)) + if (!hasFlag(EXPANDEDNAME)) { + setFlag(EXPANDEDNAME) + if (hasAccessorFlag && !isDeferred) { + accessed.expandName(base) + } + else if (hasGetter) { + getter(owner).expandName(base) + setter(owner).expandName(base) + } + name = nme.expandedName(name.toTermName, base) } - expand(this) } protected def doCookJavaRawInfo() { @@ -3235,7 +3223,6 @@ trait Symbols extends api.Symbols { self: SymbolTable => override def companionModule = NoSymbol override def companionSymbol = NoSymbol override def isSubClass(that: Symbol) = false - override def isOverridingSymbol = false override def filter(cond: Symbol => Boolean) = this override def defString: String = toString override def locationString: String = "" diff --git a/test/files/run/t6387.check b/test/files/run/t6387.check deleted file mode 100644 index 83b33d238d..0000000000 --- a/test/files/run/t6387.check +++ /dev/null @@ -1 +0,0 @@ -1000 diff --git a/test/files/run/t6387.scala b/test/files/run/t6387.scala deleted file mode 100644 index bbebb5f511..0000000000 --- a/test/files/run/t6387.scala +++ /dev/null @@ -1,16 +0,0 @@ -trait A { - def foo: Long -} - -object Test { - def a(): A = new A { - var foo: Long = 1000L - - val test = () => { - foo = 28 - } - } - def main(args: Array[String]) { - println(a().foo) - } -} diff --git a/test/files/run/t7341.check b/test/files/run/t7341.check new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/files/run/t7341.flags b/test/files/run/t7341.flags new file mode 100755 index 0000000000..ae08446055 --- /dev/null +++ b/test/files/run/t7341.flags @@ -0,0 +1 @@ +-Xcheckinit \ No newline at end of file diff --git a/test/files/run/t7341.scala b/test/files/run/t7341.scala new file mode 100755 index 0000000000..dc526c6c19 --- /dev/null +++ b/test/files/run/t7341.scala @@ -0,0 +1,15 @@ +object Obj { + private var cache: Any = () + def returning(f: () => Unit) = () + def foo { + returning(() => cache = ()) + } + + def apply(): Any = { + cache + } +} + +object Test extends App { + Obj() +} diff --git a/test/pending/run/t6387.check b/test/pending/run/t6387.check new file mode 100644 index 0000000000..83b33d238d --- /dev/null +++ b/test/pending/run/t6387.check @@ -0,0 +1 @@ +1000 diff --git a/test/pending/run/t6387.scala b/test/pending/run/t6387.scala new file mode 100644 index 0000000000..bbebb5f511 --- /dev/null +++ b/test/pending/run/t6387.scala @@ -0,0 +1,16 @@ +trait A { + def foo: Long +} + +object Test { + def a(): A = new A { + var foo: Long = 1000L + + val test = () => { + foo = 28 + } + } + def main(args: Array[String]) { + println(a().foo) + } +} -- cgit v1.2.3 From 6a61e172d9de912c74af50e49f0057fbe8d4e500 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Sat, 23 Mar 2013 15:06:22 +0100 Subject: SI-7289 Less strict type application for TypeVar. When a type constructor variable is applied to the wrong number of arguments, return a new type variable whose instance is `ErrorType`. Dissection of the reported test case by @retronym: Define the first implicit: scala> trait Schtroumpf[T] defined trait Schtroumpf scala> implicit def schtroumpf[T, U <: Coll[T], Coll[X] <: Traversable[X]] | (implicit minorSchtroumpf: Schtroumpf[T]): Schtroumpf[U] = ??? schtroumpf: [T, U <: Coll[T], Coll[X] <: Traversable[X]](implicit minorSchtroumpf: Schtroumpf[T])Schtroumpf[U] Call it explicitly => kind error during type inference reported. scala> schtroumpf(null): Schtroumpf[Int] :10: error: inferred kinds of the type arguments (Nothing,Int,Int) do not conform to the expected kinds of the type parameters (type T,type U,type Coll). Int's type parameters do not match type Coll's expected parameters: class Int has no type parameters, but type Coll has one schtroumpf(null): Schtroumpf[Int] ^ :10: error: type mismatch; found : Schtroumpf[U] required: Schtroumpf[Int] schtroumpf(null): Schtroumpf[Int] ^ Add another implicit, and let implicit search weigh them up. scala> implicitly[Schtroumpf[Int]] :10: error: diverging implicit expansion for type Schtroumpf[Int] starting with method schtroumpf implicitly[Schtroumpf[Int]] ^ scala> implicit val qoo = new Schtroumpf[Int]{} qoo: Schtroumpf[Int] = $anon$1@c1b9b03 scala> implicitly[Schtroumpf[Int]] Implicit search compares the two in-scope implicits in `isStrictlyMoreSpecific`, which constructs an existential type: type ET = Schtroumpf[U] forSome { type T; type U <: Coll[T]; type Coll[_] <: Traversable[_] } A subsequent subtype check `ET <:< Schtroumpf[Int]` gets to `withTypeVars`, which replaces the quantified types with type variables, checks conformance of that substitued underlying type against `Schtroumpf[Int]`, and then tries to solve the collected type constraints. The type var trace looks like: [ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) [ create] ?U ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) [ create] ?Coll ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) [ setInst] Nothing ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Nothing ) [ setInst] scala.collection.immutable.Nil.type( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], U=scala.collection.immutable.Nil.type ) [ setInst] =?scala.collection.immutable.Nil.type( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], Coll==?scala.collection.immutable.Nil.type ) [ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) [ setInst] Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Int ) [ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) [ create] ?U ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) [ create] ?Coll ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) [ setInst] Nothing ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Nothing ) [ setInst] Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], U=Int ) [ setInst] =?Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], Coll==?Int ) The problematic part is when `?Int` (the type var originated from `U`) is registered as a lower bound for `Coll`. That happens in `solveOne`: for (tparam2 <- tparams) tparam2.info.bounds.hi.dealias match { case TypeRef(_, `tparam`, _) => log(s"$tvar addLoBound $tparam2.tpeHK.instantiateTypeParams($tparams, $tvars)") tvar addLoBound tparam2.tpeHK.instantiateTypeParams(tparams, tvars) case _ => } --- bincompat-backward.whitelist.conf | 4 +++ bincompat-forward.whitelist.conf | 4 +++ src/reflect/scala/reflect/internal/Types.scala | 17 ++++++----- test/files/neg/t7289.check | 4 +++ test/files/neg/t7289.scala | 39 ++++++++++++++++++++++++++ test/files/neg/t7289_status_quo.check | 22 +++++++++++++++ test/files/neg/t7289_status_quo.scala | 23 +++++++++++++++ 7 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 test/files/neg/t7289.check create mode 100644 test/files/neg/t7289.scala create mode 100644 test/files/neg/t7289_status_quo.check create mode 100644 test/files/neg/t7289_status_quo.scala (limited to 'test/files') diff --git a/bincompat-backward.whitelist.conf b/bincompat-backward.whitelist.conf index aa06e1d21c..3426dc72e1 100644 --- a/bincompat-backward.whitelist.conf +++ b/bincompat-backward.whitelist.conf @@ -186,6 +186,10 @@ filter { { matchName="scala.reflect.internal.ClassfileConstants.xxxunusedxxxx" problemName=MissingMethodProblem + }, + { + matchName="scala.reflect.internal.Types#TypeVar.setInst" + problemName=IncompatibleResultTypeProblem } ] } diff --git a/bincompat-forward.whitelist.conf b/bincompat-forward.whitelist.conf index d0893c5a28..c59d0a7dec 100644 --- a/bincompat-forward.whitelist.conf +++ b/bincompat-forward.whitelist.conf @@ -418,6 +418,10 @@ filter { { matchName="scala.reflect.internal.ClassfileConstants.CONSTANT_METHODTYPE" problemName=MissingMethodProblem + }, + { + matchName="scala.reflect.internal.Types#TypeVar.setInst" + problemName=IncompatibleResultTypeProblem } ] } diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index a2c9f1fadf..ee584bed2c 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -3076,12 +3076,14 @@ trait Types extends api.Types { self: SymbolTable => /** The variable's skolemization level */ val level = skolemizationLevel - /** Two occurrences of a higher-kinded typevar, e.g. `?CC[Int]` and `?CC[String]`, correspond to - * ''two instances'' of `TypeVar` that share the ''same'' `TypeConstraint`. + /** Applies this TypeVar to type arguments, if arity matches. * - * `constr` for `?CC` only tracks type constructors anyway, - * so when `?CC[Int] <:< List[Int]` and `?CC[String] <:< Iterable[String]` - * `?CC's` hibounds contains List and Iterable. + * Different applications of the same type constructor variable `?CC`, + * e.g. `?CC[Int]` and `?CC[String]`, are modeled as distinct instances of `TypeVar` + * that share a `TypeConstraint`, so that the comparisons `?CC[Int] <:< List[Int]` + * and `?CC[String] <:< Iterable[String]` result in `?CC` being upper-bounded by `List` and `Iterable`. + * + * Applying the wrong number of type args results in a TypeVar whose instance is set to `ErrorType`. */ def applyArgs(newArgs: List[Type]): TypeVar = ( if (newArgs.isEmpty && typeArgs.isEmpty) @@ -3091,7 +3093,7 @@ trait Types extends api.Types { self: SymbolTable => TypeVar.trace("applyArgs", "In " + originLocation + ", apply args " + newArgs.mkString(", ") + " to " + originName)(tv) } else - throw new Error("Invalid type application in TypeVar: " + params + ", " + newArgs) + TypeVar(typeSymbol).setInst(ErrorType) ) // newArgs.length may differ from args.length (could've been empty before) // @@ -3121,13 +3123,14 @@ trait Types extends api.Types { self: SymbolTable => // // invariant: before mutating constr, save old state in undoLog // (undoLog is used to reset constraints to avoid piling up unrelated ones) - def setInst(tp: Type) { + def setInst(tp: Type): this.type = { // assert(!(tp containsTp this), this) undoLog record this // if we were compared against later typeskolems, repack the existential, // because skolems are only compatible if they were created at the same level val res = if (shouldRepackType) repackExistential(tp) else tp constr.inst = TypeVar.trace("setInst", "In " + originLocation + ", " + originName + "=" + res)(res) + this } def addLoBound(tp: Type, isNumericBound: Boolean = false) { diff --git a/test/files/neg/t7289.check b/test/files/neg/t7289.check new file mode 100644 index 0000000000..e4aeebbc6c --- /dev/null +++ b/test/files/neg/t7289.check @@ -0,0 +1,4 @@ +t7289.scala:8: error: could not find implicit value for parameter e: Test.Schtroumpf[scala.collection.immutable.Nil.type] + implicitly[Schtroumpf[Nil.type]] + ^ +one error found diff --git a/test/files/neg/t7289.scala b/test/files/neg/t7289.scala new file mode 100644 index 0000000000..f4ed3daf76 --- /dev/null +++ b/test/files/neg/t7289.scala @@ -0,0 +1,39 @@ +object Test extends App { + trait Schtroumpf[T] + + implicit def schtroumpf[T, U <: Coll[T], Coll[X] <: Traversable[X]] + (implicit minorSchtroumpf: Schtroumpf[T]): Schtroumpf[U] = ??? + + implicit val qoo: Schtroumpf[Int] = new Schtroumpf[Int]{} + implicitly[Schtroumpf[Nil.type]] +} + +/* +info1 = {scala.tools.nsc.typechecker.Implicits$ImplicitInfo@3468}"qoo: => Test.Schtroumpf[Int]" +info2 = {scala.tools.nsc.typechecker.Implicits$ImplicitInfo@3469}"schtroumpf: [T, U <: Coll[T], Coll[_] <: Traversable[_]](implicit minorSchtroumpf: Test.Schtroumpf[T])Test.Schtroumpf[U]" +isStrictlyMoreSpecific(info1, info2) + isSubType(Test.Schtroumpf[Int], Test.Schtroumpf[U] forSome { T; U <: Coll[T]; Coll[_] <: Traversable[_] }) + isAsSpecificValueType(Test.Schtroumpf[Int], Test.Schtroumpf[U], undef2 = List(type T, type U, type Coll)) + + val et: ExistentialType = Test.Schtroumpf[U] forSome { T; U <: Coll[T]; Coll[_] <: Traversable[_] } + val tp1 = Test.Schtroumpf[Int] + et.withTypeVars(isSubType(tp1, _, depth)) + solve() + tvars = tList(=?Nothing, =?Int, =?=?Int) + + +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?U ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?Coll ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Nothing ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Nothing ) +[ setInst] scala.collection.immutable.Nil.type( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], U=scala.collection.immutable.Nil.type ) +[ setInst] =?scala.collection.immutable.Nil.type( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], Coll==?scala.collection.immutable.Nil.type ) +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Int ) +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?U ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?Coll ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Nothing ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Nothing ) +[ setInst] Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], U=Int ) +[ setInst] =?Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], Coll==?Int ) +*/ \ No newline at end of file diff --git a/test/files/neg/t7289_status_quo.check b/test/files/neg/t7289_status_quo.check new file mode 100644 index 0000000000..31c072e969 --- /dev/null +++ b/test/files/neg/t7289_status_quo.check @@ -0,0 +1,22 @@ +t7289_status_quo.scala:9: error: could not find implicit value for parameter e: Test1.Ext[List[Int]] + implicitly[Ext[List[Int]]] // fails - not found + ^ +t7289_status_quo.scala:11: error: could not find implicit value for parameter e: Test1.Ext[List[List[List[Int]]]] + implicitly[Ext[List[List[List[Int]]]]] // fails - not found + ^ +t7289_status_quo.scala:15: error: ambiguous implicit values: + both method f in object Test1 of type [A, Coll <: CC[A], CC[X] <: Traversable[X]](implicit xi: Test1.Ext[A])Test1.Ext[Coll] + and value m in object Test1 of type => Test1.Ext[List[List[Int]]] + match expected type Test1.Ext[_ <: List[List[Int]]] + implicitly[Ext[_ <: List[List[Int]]]] // fails - ambiguous + ^ +t7289_status_quo.scala:20: error: could not find implicit value for parameter e: Test1.ExtCov[List[Int]] + implicitly[ExtCov[List[Int]]] // fails - not found + ^ +t7289_status_quo.scala:21: error: could not find implicit value for parameter e: Test1.ExtCov[List[List[Int]]] + implicitly[ExtCov[List[List[Int]]]] // fails - not found + ^ +t7289_status_quo.scala:22: error: could not find implicit value for parameter e: Test1.ExtCov[List[List[List[Int]]]] + implicitly[ExtCov[List[List[List[Int]]]]] // fails - not found + ^ +6 errors found diff --git a/test/files/neg/t7289_status_quo.scala b/test/files/neg/t7289_status_quo.scala new file mode 100644 index 0000000000..39621429a1 --- /dev/null +++ b/test/files/neg/t7289_status_quo.scala @@ -0,0 +1,23 @@ +// record the status quo after this fix +// not clear to @adriaanm why an upper-bounded existential in an invariant position +// is different from putting that upper bound in a covariant position +object Test1 { + trait Ext[T] + implicit def f[A, Coll <: CC[A], CC[X] <: Traversable[X]](implicit xi: Ext[A]): Ext[Coll] = ??? + implicit val m: Ext[List[List[Int]]] = new Ext[List[List[Int]]]{} + + implicitly[Ext[List[Int]]] // fails - not found + implicitly[Ext[List[List[Int]]]] // compiles + implicitly[Ext[List[List[List[Int]]]]] // fails - not found + + // Making Ext[+T] should incur the same behavior as these. (so says @paulp) + implicitly[Ext[_ <: List[Int]]] // compiles + implicitly[Ext[_ <: List[List[Int]]]] // fails - ambiguous + implicitly[Ext[_ <: List[List[List[Int]]]]] // compiles + + // But, we currently get: + trait ExtCov[+T] + implicitly[ExtCov[List[Int]]] // fails - not found + implicitly[ExtCov[List[List[Int]]]] // fails - not found + implicitly[ExtCov[List[List[List[Int]]]]] // fails - not found +} \ No newline at end of file -- cgit v1.2.3 From 72503126d9c29ff029c4c9537234e1fb1d7a0130 Mon Sep 17 00:00:00 2001 From: Uladzimir Abramchuk Date: Fri, 15 Feb 2013 17:19:21 +0300 Subject: SI-6386 typed existential type tree's original now have tpe set Tree reification fails for ExistentialTypeTree. The reason is that the tree passed for reification (see reifyTree at GetTrees.scala) must have not null tpe (see reifyBoundType at GenTrees.scala), which is not true in the case of ExistentialTypeTree. Why is it so? The tree passed to reifyTree was obtained in the reshape phase of reificationusing using original TypeTrees that reporesent pre- typer representation of a type. The problem is that original's tpe for ExistentialTypeTree is not set. So the solution to the issue is to create ExistentialTypeTree's original in a such way that is has actual tpe set. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 12 ++++++++++-- test/files/pos/t6386.scala | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/files/pos/t6386.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 34ba8b46f9..d1d6feae97 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3887,8 +3887,16 @@ trait Typers extends Modes with Adaptations with Tags { if (vd.symbol.tpe.isVolatile) AbstractionFromVolatileTypeError(vd) val tpt1 = typedType(tree.tpt, mode) - existentialTransform(tree.whereClauses map (_.symbol), tpt1.tpe)((tparams, tp) => - TypeTree(newExistentialType(tparams, tp)) setOriginal tree + existentialTransform(tree.whereClauses map (_.symbol), tpt1.tpe)((tparams, tp) => { + val original = tpt1 match { + case tpt : TypeTree => atPos(tree.pos)(ExistentialTypeTree(tpt.original, tree.whereClauses)) + case _ => { + debuglog(s"cannot reconstruct the original for $tree, because $tpt1 is not a TypeTree") + tree + } + } + TypeTree(newExistentialType(tparams, tp)) setOriginal original + } ) } diff --git a/test/files/pos/t6386.scala b/test/files/pos/t6386.scala new file mode 100644 index 0000000000..85098a78f0 --- /dev/null +++ b/test/files/pos/t6386.scala @@ -0,0 +1,5 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + reify(manifest[Some[_]]) +} \ No newline at end of file -- cgit v1.2.3 From 67c2d6df8141d77c7ac04aa6f97cbc6e53684473 Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Wed, 10 Apr 2013 14:34:08 +0400 Subject: SI-6286 IllegalArgumentException handling specialized method. Specialize assigns SpecialOverride info to a specialized method even when there is a further specialization that should be forwarded to. --- .../tools/nsc/transform/SpecializeTypes.scala | 37 ++++++++++------------ test/files/pos/spec-t6286.scala | 10 ++++++ 2 files changed, 27 insertions(+), 20 deletions(-) create mode 100755 test/files/pos/spec-t6286.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index a71920f787..07b1cb4206 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -976,27 +976,24 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { debuglog("specialized overload %s for %s in %s: %s".format(om, overriding.name.decode, pp(env), om.info)) typeEnv(om) = env addConcreteSpecMethod(overriding) - info(om) = ( - if (overriding.isDeferred) { // abstract override - debuglog("abstract override " + overriding.fullName + " with specialized " + om.fullName) - Forward(overriding) - } - else { - // if the override is a normalized member, 'om' gets the - // implementation from its original target, and adds the - // environment of the normalized member (that is, any - // specialized /method/ type parameter bindings) - val impl = info get overriding match { - case Some(NormalizedMember(target)) => - typeEnv(om) = env ++ typeEnv(overriding) - target - case _ => - overriding - } - info(overriding) = Forward(om setPos overriding.pos) - SpecialOverride(impl) + if (overriding.isDeferred) { // abstract override + debuglog("abstract override " + overriding.fullName + " with specialized " + om.fullName) + info(om) = Forward(overriding) + } + else { + // if the override is a normalized member, 'om' gets the + // implementation from its original target, and adds the + // environment of the normalized member (that is, any + // specialized /method/ type parameter bindings) + info get overriding match { + case Some(NormalizedMember(target)) => + typeEnv(om) = env ++ typeEnv(overriding) + info(om) = Forward(target) + case _ => + info(om) = SpecialOverride(overriding) } - ) + info(overriding) = Forward(om setPos overriding.pos) + } newOverload(overriding, om, env) ifDebug(afterSpecialize(assert( overridden.owner.info.decl(om.name) != NoSymbol, diff --git a/test/files/pos/spec-t6286.scala b/test/files/pos/spec-t6286.scala new file mode 100755 index 0000000000..4d87998ec6 --- /dev/null +++ b/test/files/pos/spec-t6286.scala @@ -0,0 +1,10 @@ +trait Foo[@specialized(Int) A] { + def fun[@specialized(Int) B](init: B)(f: (B, A) => B): B +} + +class Bar(values: Array[Int]) extends Foo[Int] { + def fun[@specialized(Int) C](init: C)(f: (C, Int) => C): C = { + val arr = values + f(init, arr(0)) + } +} -- cgit v1.2.3