diff options
55 files changed, 683 insertions, 61 deletions
diff --git a/src/compiler/scala/reflect/reify/codegen/Types.scala b/src/compiler/scala/reflect/reify/codegen/Types.scala index 1f336f4b0f..a2b074c6b2 100644 --- a/src/compiler/scala/reflect/reify/codegen/Types.scala +++ b/src/compiler/scala/reflect/reify/codegen/Types.scala @@ -99,7 +99,7 @@ trait Types { // if this fails, it might produce the dreaded "erroneous or inaccessible type" error // to find out the whereabouts of the error run scalac with -Ydebug if (reifyDebug) println("launching implicit search for %s.%s[%s]".format(prefix, tagClass.name, tpe)) - typer.resolveTypeTag(defaultErrorPosition, prefix.tpe, tpe, concrete) match { + typer.resolveTypeTag(prefix.tpe, tpe, defaultErrorPosition, concrete) match { case failure if failure.isEmpty => if (reifyDebug) println("implicit search was fruitless") EmptyTree diff --git a/src/compiler/scala/reflect/reify/package.scala b/src/compiler/scala/reflect/reify/package.scala index 3f9d6200cd..f3040ad79c 100644 --- a/src/compiler/scala/reflect/reify/package.scala +++ b/src/compiler/scala/reflect/reify/package.scala @@ -33,8 +33,8 @@ package object reify { import definitions._ import analyzer.enclosingMacroPosition - def erasureTagInScope = typer0.context.withMacrosDisabled(typer0.resolveErasureTag(enclosingMacroPosition, tpe, concrete = concrete)) - def arrayTagInScope = typer0.context.withMacrosDisabled(typer0.resolveArrayTag(enclosingMacroPosition, tpe)) + def erasureTagInScope = typer0.context.withMacrosDisabled(typer0.resolveErasureTag(tpe, enclosingMacroPosition, concrete = concrete)) + def arrayTagInScope = typer0.context.withMacrosDisabled(typer0.resolveArrayTag(tpe, enclosingMacroPosition)) val inScope = (erasureTagInScope, arrayTagInScope) inScope match { diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 338c39dc5f..b8e43dfc50 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -997,7 +997,7 @@ abstract class Erasure extends AddInterfaces } // Rewrite 5.getClass to ScalaRunTime.anyValClass(5) else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) - global.typer.typed(gen.mkRuntimeCall(nme.anyValClass, List(qual, typer.resolveErasureTag(tree.pos, qual.tpe.widen, true)))) + global.typer.typed(gen.mkRuntimeCall(nme.anyValClass, List(qual, typer.resolveErasureTag(qual.tpe.widen, tree.pos, true)))) else tree diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index f6296acdca..e0f34b47c8 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -752,9 +752,10 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { } } } - + val subclasses = specializations(clazz.info.typeParams) filter satisfiable - subclasses foreach { env => + subclasses foreach { + env => val spc = specializedClass(env, decls1) val existing = clazz.owner.info.decl(spc.name) @@ -928,7 +929,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { if (currentRun compiles overriding) checkOverriddenTParams(overridden) - val env = unify(overridden.info, overriding.info, emptyEnv, false) + val env = unify(overridden.info, overriding.info, emptyEnv, false, true) def atNext = afterSpecialize(overridden.owner.info.decl(specializedName(overridden, env))) if (TypeEnv.restrict(env, stvars).nonEmpty && TypeEnv.isValid(env, overridden) && atNext != NoSymbol) { @@ -990,8 +991,10 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { * Fails if such an environment cannot be found. * * If `strict` is true, a UnifyError is thrown if unification is impossible. + * + * If `tparams` is true, then the methods tries to unify over type params in polytypes as well. */ - private def unify(tp1: Type, tp2: Type, env: TypeEnv, strict: Boolean): TypeEnv = (tp1, tp2) match { + private def unify(tp1: Type, tp2: Type, env: TypeEnv, strict: Boolean, tparams: Boolean = false): TypeEnv = (tp1, tp2) match { case (TypeRef(_, sym1, _), _) if sym1.isSpecialized => debuglog("Unify " + tp1 + ", " + tp2) if (isPrimitiveValueClass(tp2.typeSymbol) || isSpecializedAnyRefSubtype(tp2, sym1)) @@ -1020,17 +1023,20 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { debuglog("Unify polytypes " + tp1 + " and " + tp2) if (strict && tparams1.length != tparams2.length) unifyError(tp1, tp2) + else if (tparams && tparams1.length == tparams2.length) + unify(res1 :: tparams1.map(_.info), res2 :: tparams2.map(_.info), env, strict) else unify(res1, res2, env, strict) - case (PolyType(_, res), other) => unify(res, other, env, strict) - case (ThisType(_), ThisType(_)) => env - case (_, SingleType(_, _)) => unify(tp1, tp2.underlying, env, strict) - case (SingleType(_, _), _) => unify(tp1.underlying, tp2, env, strict) - case (ThisType(_), _) => unify(tp1.widen, tp2, env, strict) - case (_, ThisType(_)) => unify(tp1, tp2.widen, env, strict) - case (RefinedType(_, _), RefinedType(_, _)) => env - case (AnnotatedType(_, tp1, _), tp2) => unify(tp2, tp1, env, strict) - case (ExistentialType(_, res1), _) => unify(tp2, res1, env, strict) + case (PolyType(_, res), other) => unify(res, other, env, strict) + case (ThisType(_), ThisType(_)) => env + case (_, SingleType(_, _)) => unify(tp1, tp2.underlying, env, strict) + case (SingleType(_, _), _) => unify(tp1.underlying, tp2, env, strict) + case (ThisType(_), _) => unify(tp1.widen, tp2, env, strict) + case (_, ThisType(_)) => unify(tp1, tp2.widen, env, strict) + case (RefinedType(_, _), RefinedType(_, _)) => env + case (AnnotatedType(_, tp1, _), tp2) => unify(tp2, tp1, env, strict) + case (ExistentialType(_, res1), _) => unify(tp2, res1, env, strict) + case (TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) => unify(List(lo1, hi1), List(lo2, hi2), env, strict) case _ => debuglog("don't know how to unify %s [%s] with %s [%s]".format(tp1, tp1.getClass, tp2, tp2.getClass)) env diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index cf00ee6b5d..ef98935f9c 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -410,23 +410,23 @@ abstract class UnCurry extends InfoTransform def sequenceToArray(tree: Tree) = { val toArraySym = tree.tpe member nme.toArray assert(toArraySym != NoSymbol) - def getClassTag(tp: Type): Tree = { - val tag = localTyper.resolveArrayTag(tree.pos, tp) + def getArrayTag(tp: Type): Tree = { + val tag = localTyper.resolveArrayTag(tp, tree.pos) // Don't want bottom types getting any further than this (SI-4024) - if (tp.typeSymbol.isBottomClass) getClassTag(AnyClass.tpe) + if (tp.typeSymbol.isBottomClass) getArrayTag(AnyClass.tpe) else if (!tag.isEmpty) tag - else if (tp.bounds.hi ne tp) getClassTag(tp.bounds.hi) - else localTyper.TyperErrorGen.MissingClassTagError(tree, tp) + else if (tp.bounds.hi ne tp) getArrayTag(tp.bounds.hi) + else localTyper.TyperErrorGen.MissingArrayTagError(tree, tp) } - def traversableClassTag(tpe: Type): Tree = { + def traversableArrayTag(tpe: Type): Tree = { (tpe baseType TraversableClass).typeArgs match { - case targ :: _ => getClassTag(targ) + case targ :: _ => getArrayTag(targ) case _ => EmptyTree } } afterUncurry { localTyper.typedPos(pos) { - gen.mkMethodCall(tree, toArraySym, Nil, List(traversableClassTag(tree.tpe))) + gen.mkMethodCall(tree, toArraySym, Nil, List(traversableArrayTag(tree.tpe))) } } } diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 6932030fc2..08bf581256 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -343,7 +343,7 @@ trait ContextErrors { issueNormalTypeError(tree, "macros cannot be eta-expanded") setError(tree) } - + def MacroPartialApplicationError(tree: Tree) = { issueNormalTypeError(tree, "macros cannot be partially applied") setError(tree) @@ -592,9 +592,9 @@ trait ContextErrors { def AbstractExistentiallyOverParamerizedTpeError(tree: Tree, tp: Type) = issueNormalTypeError(tree, "can't existentially abstract over parameterized type " + tp) - // classTagTree - def MissingClassTagError(tree: Tree, tp: Type) = { - issueNormalTypeError(tree, "cannot find class tag for element type "+tp) + // resolveArrayTag + def MissingArrayTagError(tree: Tree, tp: Type) = { + issueNormalTypeError(tree, "cannot find array tag for element type "+tp) setError(tree) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 787d7af136..722440349a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1266,8 +1266,8 @@ trait Implicits { } val tagInScope = - if (full) context.withMacrosDisabled(resolveTypeTag(pos, ReflectMirrorPrefix.tpe, tp, true)) - else context.withMacrosDisabled(resolveArrayTag(pos, tp)) + if (full) context.withMacrosDisabled(resolveTypeTag(ReflectMirrorPrefix.tpe, tp, pos, true)) + else context.withMacrosDisabled(resolveArrayTag(tp, pos)) if (tagInScope.isEmpty) mot(tp, Nil, Nil) else { val interop = diff --git a/src/compiler/scala/tools/nsc/typechecker/Taggings.scala b/src/compiler/scala/tools/nsc/typechecker/Taggings.scala index d276b39f16..fb0d6fb3c5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Taggings.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Taggings.scala @@ -10,7 +10,7 @@ trait Taggings { trait Tagging { self: Typer => - private def resolveTag(pos: Position, taggedTp: Type) = beforeTyper { + private def resolveTag(taggedTp: Type, pos: Position) = beforeTyper { inferImplicit( EmptyTree, taggedTp, @@ -25,47 +25,47 @@ trait Taggings { /** Finds in scope or materializes an ArrayTag. * Should be used instead of ClassTag or ClassManifest every time compiler needs to create an array. * + * @param tp Type we're looking an ArrayTag for, e.g. resolveArrayTag(IntClass.tpe, pos) will look for ArrayTag[Int]. * @param pos Position for error reporting. Please, provide meaningful value. - * @param tp Type we're looking an ArrayTag for, e.g. resolveArrayTag(pos, IntClass.tpe) will look for ArrayTag[Int]. * * @returns Tree that represents an `scala.reflect.ArrayTag` for `tp` if everything is okay. * EmptyTree if the result contains unresolved (i.e. not spliced) type parameters and abstract type members. */ - def resolveArrayTag(pos: Position, tp: Type): Tree = { + def resolveArrayTag(tp: Type, pos: Position): Tree = { val taggedTp = appliedType(ArrayTagClass.typeConstructor, List(tp)) - resolveTag(pos, taggedTp) + resolveTag(taggedTp, pos) } /** Finds in scope or materializes an ErasureTag (if `concrete` is false) or a ClassTag (if `concrete` is true). * Should be used instead of ClassTag or ClassManifest every time compiler needs to persist an erasure. * + * @param tp Type we're looking an ErasureTag for, e.g. resolveErasureTag(IntClass.tpe, pos, true) will look for ClassTag[Int]. * @param pos Position for error reporting. Please, provide meaningful value. - * @param tp Type we're looking an ErasureTag for, e.g. resolveErasureTag(pos, IntClass.tpe, true) will look for ClassTag[Int]. * @param concrete If true then the result must not contain unresolved (i.e. not spliced) type parameters and abstract type members. * If false then the function will always succeed (abstract types will be erased to their upper bounds). * * @returns Tree that represents an `scala.reflect.ErasureTag` for `tp` if everything is okay. * EmptyTree if `concrete` is true and the result contains unresolved (i.e. not spliced) type parameters and abstract type members. */ - def resolveErasureTag(pos: Position, tp: Type, concrete: Boolean): Tree = { + def resolveErasureTag(tp: Type, pos: Position, concrete: Boolean): Tree = { val taggedTp = appliedType(if (concrete) ClassTagClass.typeConstructor else ErasureTagClass.typeConstructor, List(tp)) - resolveTag(pos, taggedTp) + resolveTag(taggedTp, pos) } /** Finds in scope or materializes a TypeTag (if `concrete` is false) or a ConcreteTypeTag (if `concrete` is true). * - * @param pos Position for error reporting. Please, provide meaningful value. * @param pre Prefix that represents a universe this type tag will be bound to. - * @param tp Type we're looking a TypeTag for, e.g. resolveTypeTag(pos, reflectMirrorPrefix, IntClass.tpe, false) will look for scala.reflect.mirror.TypeTag[Int]. + * @param tp Type we're looking a TypeTag for, e.g. resolveTypeTag(reflectMirrorPrefix, IntClass.tpe, pos, false) will look for scala.reflect.mirror.TypeTag[Int]. + * @param pos Position for error reporting. Please, provide meaningful value. * @param concrete If true then the result must not contain unresolved (i.e. not spliced) type parameters and abstract type members. * If false then the function will always succeed (abstract types will be reified as free types). * * @returns Tree that represents a `scala.reflect.TypeTag` for `tp` if everything is okay. * EmptyTree if `concrete` is true and the result contains unresolved (i.e. not spliced) type parameters and abstract type members. */ - def resolveTypeTag(pos: Position, pre: Type, tp: Type, concrete: Boolean): Tree = { + def resolveTypeTag(pre: Type, tp: Type, pos: Position, concrete: Boolean): Tree = { val taggedTp = appliedType(singleType(pre, pre member (if (concrete) ConcreteTypeTagClass else TypeTagClass).name), List(tp)) - resolveTag(pos, taggedTp) + resolveTag(taggedTp, pos) } } }
\ No newline at end of file diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 5902e480a3..8c2eae1c86 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -4841,8 +4841,8 @@ trait Typers extends Modes with Adaptations with Taggings { val Some((level, componentType)) = erasure.GenericArray.unapply(tpt.tpe) val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.asType, List(tpe))).last val newArrayApp = atPos(tree.pos) { - val tag = resolveArrayTag(tree.pos, tagType) - if (tag.isEmpty) MissingClassTagError(tree, tagType) + val tag = resolveArrayTag(tagType, tree.pos) + if (tag.isEmpty) MissingArrayTagError(tree, tagType) else new ApplyToImplicitArgs(Select(tag, nme.newArray), args) } typed(newArrayApp, mode, pt) diff --git a/src/library/scala/DelayedInit.scala b/src/library/scala/DelayedInit.scala index e898bca720..52a38ca6f7 100644 --- a/src/library/scala/DelayedInit.scala +++ b/src/library/scala/DelayedInit.scala @@ -8,15 +8,41 @@ package scala -/** Classes and traits inheriting the `DelayedInit` marker trait - * will have their initialization code rewritten as follows: +/** Classes and objects (but note, not traits) inheriting the `DelayedInit` + * marker trait will have their initialization code rewritten as follows: * `code` becomes `delayedInit(code)`. * * Initialization code comprises all statements and all value definitions * that are executed during initialization. * + * Example: + * {{{ + * trait Helper extends DelayedInit { + * def delayedInit(body: => Unit) = { + * println("dummy text, printed before initialization of C") + * body // evaluates the initialization code of C + * } + * } + * + * class C extends Helper { + * println("this is the initialization code of C") + * } + * + * object Test extends App { + * val c = new C + * } + * }}} + * + * Should result in the following being printed: + * {{{ + * dummy text, printed before initialization of C + * this is the initialization code of C + * }}} + * + * @see "Delayed Initialization" subsection of the Scala Language Specification (section 5.1) + * * @author Martin Odersky */ trait DelayedInit { def delayedInit(x: => Unit): Unit -} +}
\ No newline at end of file diff --git a/src/library/scala/collection/GenIterableLike.scala b/src/library/scala/collection/GenIterableLike.scala index 79113ddaa7..290a3b26b5 100644 --- a/src/library/scala/collection/GenIterableLike.scala +++ b/src/library/scala/collection/GenIterableLike.scala @@ -141,7 +141,4 @@ trait GenIterableLike[+A, +Repr] extends Any with GenTraversableLike[A, Repr] { */ def zipAll[B, A1 >: A, That](that: GenIterable[B], thisElem: A1, thatElem: B)(implicit bf: CBF[Repr, (A1, B), That]): That - def isEmpty = iterator.isEmpty - - def head = iterator.next } diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala index 903594b69d..df652f99d9 100644 --- a/src/library/scala/collection/GenTraversableLike.scala +++ b/src/library/scala/collection/GenTraversableLike.scala @@ -59,12 +59,24 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with def size: Int + /** Selects the first element of this $coll. + * $orderDependent + * @return the first element of this $coll. + * @throws `NoSuchElementException` if the $coll is empty. + */ def head: A - + + /** Optionally selects the first element. + * $orderDependent + * @return the first element of this $coll if it is nonempty, + * `None` if it is empty. + */ + def headOption: Option[A] + /** Tests whether this $coll can be repeatedly traversed. * @return `true` */ - final def isTraversableAgain = true + def isTraversableAgain: Boolean /** Selects all elements except the first. * $orderDependent @@ -72,11 +84,30 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with * except the first one. * @throws `UnsupportedOperationException` if the $coll is empty. */ - def tail: Repr = { - if (isEmpty) throw new UnsupportedOperationException("empty.tail") - drop(1) - } + def tail: Repr + /** Selects the last element. + * $orderDependent + * @return The last element of this $coll. + * @throws NoSuchElementException If the $coll is empty. + */ + def last: A + + /** Optionally selects the last element. + * $orderDependent + * @return the last element of this $coll$ if it is nonempty, + * `None` if it is empty. + */ + def lastOption: Option[A] + + /** Selects all elements except the last. + * $orderDependent + * @return a $coll consisting of all elements of this $coll + * except the last one. + * @throws `UnsupportedOperationException` if the $coll is empty. + */ + def init: Repr + /** Computes a prefix scan of the elements of the collection. * * Note: The neutral element `z` may be applied more than once. diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index 3ca4bfeee9..3716a318d9 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -84,6 +84,8 @@ trait TraversableLike[+A, +Repr] extends Any */ def repr: Repr = this.asInstanceOf[Repr] + final def isTraversableAgain: Boolean = true + /** The underlying collection seen as an instance of `$Coll`. * By default this is implemented as the current collection object itself, * but this can be overridden. diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index 014b9b1a42..4cb229fc0f 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -178,10 +178,30 @@ self: ParIterableLike[T, Repr, Sequential] => def repr: Repr = this.asInstanceOf[Repr] + final def isTraversableAgain = true + def hasDefiniteSize = true + def isEmpty = size == 0 + def nonEmpty = size != 0 - + + def head = iterator.next + + def headOption = if (nonEmpty) Some(head) else None + + def tail = drop(1) + + def last = { + var lst = head + for (x <- this.seq) lst = x + lst + } + + def lastOption = if (nonEmpty) Some(last) else None + + def init = take(size - 1) + /** Creates a new parallel iterator used to traverse the elements of this parallel collection. * This iterator is more specific than the iterator of the returned by `iterator`, and augmented * with additional accessor and transformer methods. diff --git a/test/files/neg/t2775.check b/test/files/neg/t2775.check index f357221cd9..a1e950cf73 100644 --- a/test/files/neg/t2775.check +++ b/test/files/neg/t2775.check @@ -1,4 +1,4 @@ -t2775.scala:1: error: cannot find class tag for element type B.this.T
-trait B[S] { type T = S; val c = new Array[T](1) }
- ^
-one error found
+t2775.scala:1: error: cannot find array tag for element type B.this.T +trait B[S] { type T = S; val c = new Array[T](1) } + ^ +one error found diff --git a/test/files/neg/t4568.check b/test/files/neg/t4568.check new file mode 100644 index 0000000000..f94d699486 --- /dev/null +++ b/test/files/neg/t4568.check @@ -0,0 +1,4 @@ +t4568.scala:8: error: recursive method isSubListOf needs result type + case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1))) + ^ +one error found diff --git a/test/files/neg/t4568.scala b/test/files/neg/t4568.scala new file mode 100644 index 0000000000..8067759262 --- /dev/null +++ b/test/files/neg/t4568.scala @@ -0,0 +1,13 @@ +object SubList { + implicit def sublistable[A](x: List[A]) = new SubListable(x) + + class SubListable[A](x: List[A]) { + def isSubListOf(y: List[A]) = { + x match { + case Nil => true + case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1))) + } + } + } + +}
\ No newline at end of file diff --git a/test/files/neg/t750.check b/test/files/neg/t750.check new file mode 100644 index 0000000000..c17ca334e6 --- /dev/null +++ b/test/files/neg/t750.check @@ -0,0 +1,15 @@ +Test_2.scala:4: error: type mismatch; + found : Array[Int] + required: Array[? with Object] +Note: Int >: ? with Object, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10) + AO_1.f(a) + ^ +Test_2.scala:5: error: type mismatch; + found : Array[Int] + required: Array[Int] +Note: Int >: Int, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: Int`. (SLS 3.2.10) + AO_1.f[Int](a) + ^ +two errors found diff --git a/test/files/neg/t750/AO_1.java b/test/files/neg/t750/AO_1.java new file mode 100644 index 0000000000..4c7360ec6f --- /dev/null +++ b/test/files/neg/t750/AO_1.java @@ -0,0 +1,5 @@ +public class AO_1 { + public static <T> void f(T[] ar0) { + System.out.println(ar0); + } +}
\ No newline at end of file diff --git a/test/files/neg/t750/Test_2.scala b/test/files/neg/t750/Test_2.scala new file mode 100644 index 0000000000..80977431c5 --- /dev/null +++ b/test/files/neg/t750/Test_2.scala @@ -0,0 +1,6 @@ +// t750 +object Test extends App { + val a = Array(1, 2, 3) + AO_1.f(a) + AO_1.f[Int](a) +} diff --git a/test/files/neg/t750b.check b/test/files/neg/t750b.check new file mode 100644 index 0000000000..72a249191e --- /dev/null +++ b/test/files/neg/t750b.check @@ -0,0 +1,15 @@ +Test.scala:4: error: type mismatch; + found : Array[Int] + required: Array[? with Object] +Note: Int >: ? with Object, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10) + AO.f(a) + ^ +Test.scala:5: error: type mismatch; + found : Array[Int] + required: Array[Int] +Note: Int >: Int, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: Int`. (SLS 3.2.10) + AO.f[Int](a) + ^ +two errors found diff --git a/test/files/neg/t750b/AO.java b/test/files/neg/t750b/AO.java new file mode 100644 index 0000000000..060baf9a3c --- /dev/null +++ b/test/files/neg/t750b/AO.java @@ -0,0 +1,5 @@ +public class AO { + public static <T> void f(T[] ar0) { + System.out.println(ar0); + } +}
\ No newline at end of file diff --git a/test/files/neg/t750b/Test.scala b/test/files/neg/t750b/Test.scala new file mode 100644 index 0000000000..5f792a7be8 --- /dev/null +++ b/test/files/neg/t750b/Test.scala @@ -0,0 +1,6 @@ +// t750 +object Test extends App { + val a = Array(1, 2, 3) + AO.f(a) + AO.f[Int](a) +} diff --git a/test/files/pos/gen-traversable-methods.scala b/test/files/pos/gen-traversable-methods.scala new file mode 100644 index 0000000000..2604a09f11 --- /dev/null +++ b/test/files/pos/gen-traversable-methods.scala @@ -0,0 +1,20 @@ + + + +import collection._ + + + +object Test { + + def main(args: Array[String]) { + val gen: GenTraversable[Int] = List(1, 2, 3) + gen.head + gen.headOption + gen.tail + gen.last + gen.lastOption + gen.init + } + +} diff --git a/test/files/run/t5629.check b/test/files/run/t5629.check new file mode 100644 index 0000000000..6a2d630f4e --- /dev/null +++ b/test/files/run/t5629.check @@ -0,0 +1,2 @@ +int child got: 33 +any child got: 33 diff --git a/test/files/run/t5629.scala b/test/files/run/t5629.scala new file mode 100644 index 0000000000..69feddd3a5 --- /dev/null +++ b/test/files/run/t5629.scala @@ -0,0 +1,36 @@ + + + +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) + } + +} diff --git a/test/files/run/t5629b.check b/test/files/run/t5629b.check new file mode 100644 index 0000000000..1bc0248c3d --- /dev/null +++ b/test/files/run/t5629b.check @@ -0,0 +1,10 @@ +=== pf(1): +MySmartPF.apply entered... +newPF.applyOrElse entered... +default +scala.MatchError: () (of class scala.runtime.BoxedUnit) +=== pf(42): +MySmartPF.apply entered... +newPF.applyOrElse entered... +ok +=== done diff --git a/test/files/run/t5629b.scala b/test/files/run/t5629b.scala new file mode 100644 index 0000000000..6c908081b9 --- /dev/null +++ b/test/files/run/t5629b.scala @@ -0,0 +1,41 @@ + + + + + +object Test extends App { + + trait MyPF[@specialized(Int) -A] extends (A => Unit) { + def isDefinedAt(x: A): Boolean + def applyOrElse[A1 <: A](x: A1, default: A1 => Unit): Unit = { + println("MyPF.applyOrElse entered...") + if (isDefinedAt(x)) apply(x) else default(x) + } + } + + trait MySmartPF[@specialized(Int) -A] extends MyPF[A] { + def apply(x: A): Unit = { + println("MySmartPF.apply entered...") + applyOrElse(x, { _: Any => throw new MatchError }) + } + } + + type T = Int + //type T = Any + + def newPF(test: T): MyPF[T] = new MySmartPF[T] { + def isDefinedAt(x: T): Boolean = x != test + override def applyOrElse[A1 <: T](x: A1, default: A1 => Unit): Unit = { + println("newPF.applyOrElse entered...") + if (x != test) { println("ok"); () } else { println("default"); default(x) } + } + } + + val pf = newPF(1) + println("=== pf(1):") + try { pf(1) } catch { case x => println(x) } + println("=== pf(42):") + pf(42) + println("=== done") + +} diff --git a/test/pending/neg/t1557.scala b/test/pending/neg/t1557.scala new file mode 100644 index 0000000000..ba93b45fad --- /dev/null +++ b/test/pending/neg/t1557.scala @@ -0,0 +1,18 @@ +object Test extends App { + trait A + trait B extends A + + trait C { + trait D { type T >: B <: A } + val y: (D with this.type)#T = new B { } + } + + class D extends C { + trait E + type T = E + def frob(arg : E) : E = arg + frob(y) + } + + new D +}
\ No newline at end of file diff --git a/test/pending/neg/t2066.scala b/test/pending/neg/t2066.scala new file mode 100644 index 0000000000..46177b19f7 --- /dev/null +++ b/test/pending/neg/t2066.scala @@ -0,0 +1,16 @@ +object Test extends App { + trait A { + def f[T[_]](x : T[Int]) : T[Any] + } + + class B extends A { + def f[T[+_]](x : T[Int]) : T[Any] = x + } + + class P[Y](var y : Y) + + val p = new P(1) + val palias = (new B():A).f[P](p) + palias.y = "hello" + val z: Int = p.y +}
\ No newline at end of file diff --git a/test/pending/pos/t5503.flags b/test/pending/pos/t5503.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/pending/pos/t5503.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/pending/pos/t5503.scala b/test/pending/pos/t5503.scala new file mode 100644 index 0000000000..8a1925df1f --- /dev/null +++ b/test/pending/pos/t5503.scala @@ -0,0 +1,18 @@ +trait A { + type Type + type MethodType <: Type + + val MethodType: MethodTypeExtractor = null + + abstract class MethodTypeExtractor { + def unapply(tpe: MethodType): Option[(Any, Any)] + } +} + +object Test { + val a: A = null + + def foo(tpe: a.Type) = tpe match { + case a.MethodType(_, _) => + } +}
\ No newline at end of file diff --git a/test/pending/pos/t5521.scala b/test/pending/pos/t5521.scala new file mode 100644 index 0000000000..dc025d0945 --- /dev/null +++ b/test/pending/pos/t5521.scala @@ -0,0 +1,3 @@ +class Foo { type Bar } + +class Quux(val foo: Foo)(val bar: foo.Bar)
\ No newline at end of file diff --git a/test/pending/pos/t5534.scala b/test/pending/pos/t5534.scala new file mode 100644 index 0000000000..834c4fd68d --- /dev/null +++ b/test/pending/pos/t5534.scala @@ -0,0 +1,11 @@ +object Phrase extends Enumeration { + type Phrase = Value + val PHRASE1 = Value("My phrase 1") + val PHRASE2 = Value("My phrase 2") +} + +class Entity(text:String) + +object Test { + val myMapWithPhrases = Phrase.values.map(p => (p -> new Entity(p.toString))).toMap +}
\ No newline at end of file diff --git a/test/pending/pos/t5579.scala b/test/pending/pos/t5579.scala new file mode 100644 index 0000000000..a1ee077fe7 --- /dev/null +++ b/test/pending/pos/t5579.scala @@ -0,0 +1,29 @@ +import language.existentials + +class Result[+A] + +case class Success[A](x: A) extends Result[A] + +class Apply[A] + +object Apply { + def apply[A](f: Int => Result[A]): Apply[A] = new Apply[A] +} + +object TestUnit { + //Error is here: + def goo = Apply { i => + i match { + case 1 => Success(Some(1)) + case _ => Success(None) + } + } + + //If type is defined explicitly (which I wanted from compiler to infer), then all is ok + def foo = Apply[t forSome { type t >: Some[Int] with None.type <: Option[Int] }] { i => + i match { + case 1 => Success(Some(1)) + case _ => Success(None) + } + } +} diff --git a/test/pending/pos/t5585.scala b/test/pending/pos/t5585.scala new file mode 100644 index 0000000000..5d3eb86111 --- /dev/null +++ b/test/pending/pos/t5585.scala @@ -0,0 +1,18 @@ +class Result[+A] + +case class Success[A](x: A) extends Result[A] + +class Apply[A] + +object Apply { + def apply[A](f: Int => Result[A]): Apply[A] = new Apply[A] +} + +object TestUnit { + def goo : Apply[Option[Int]] = Apply { i => + val p = i match { + case 1 => Success(Some(1)) + case _ => Success(None) + } + } +}
\ No newline at end of file diff --git a/test/pending/pos/t5639/Bar.scala b/test/pending/pos/t5639/Bar.scala new file mode 100644 index 0000000000..f577500acd --- /dev/null +++ b/test/pending/pos/t5639/Bar.scala @@ -0,0 +1,7 @@ +package pack.age + +import pack.age.Implicits._ + +object Quux { + def baz : Baz = 1 +} diff --git a/test/pending/pos/t5639/Foo.scala b/test/pending/pos/t5639/Foo.scala new file mode 100644 index 0000000000..6602150661 --- /dev/null +++ b/test/pending/pos/t5639/Foo.scala @@ -0,0 +1,7 @@ +package pack.age + +class Baz + +object Implicits { + implicit def Baz(n: Int): Baz = new Baz +} diff --git a/test/pending/pos/t5654.scala b/test/pending/pos/t5654.scala new file mode 100644 index 0000000000..eb711a5f37 --- /dev/null +++ b/test/pending/pos/t5654.scala @@ -0,0 +1,4 @@ +case class Bomb(a: Array[_]) +case class Bomb2(a: Array[T] forSome { type T }) +class Okay1(a: Array[_]) +case class Okay2(s: Seq[_])
\ No newline at end of file diff --git a/test/pending/pos/t5712.scala b/test/pending/pos/t5712.scala new file mode 100644 index 0000000000..31f365028a --- /dev/null +++ b/test/pending/pos/t5712.scala @@ -0,0 +1,14 @@ +import scala.tools.nsc._ + +object Test { + + // works + def mkReifier(global: Global)(typer: global.analyzer.Typer) = typer + +/* +<console>:10: error: not found: value global + class Reifier(global: Global)(typer: global.analyzer.Typer) { } +*/ + class Reifier(global: Global)(typer: global.analyzer.Typer) { } + +} diff --git a/test/pending/presentation/t5708.check b/test/pending/presentation/t5708.check new file mode 100644 index 0000000000..9d944d6cfc --- /dev/null +++ b/test/pending/presentation/t5708.check @@ -0,0 +1,81 @@ +reload: Completions.scala + +askTypeCompletion at Completions.scala(9,9) +================================================================================ +[response] aksTypeCompletion at (9,9) +retrieved 38 members +[accessible: true] `method !=(x$1: Any)Boolean` +[accessible: true] `method !=(x$1: AnyRef)Boolean` +[accessible: true] `method ##()Int` +[accessible: true] `method +(other: String)String` +[accessible: true] `method ->[B](y: B)(test.Compat.type, B)` +[accessible: true] `method ==(x$1: Any)Boolean` +[accessible: true] `method ==(x$1: AnyRef)Boolean` +[accessible: true] `method asInstanceOf[T0]=> T0` +[accessible: true] `method ensuring(cond: Boolean)test.Compat.type` +[accessible: true] `method ensuring(cond: Boolean, msg: => Any)test.Compat.type` +[accessible: true] `method ensuring(cond: test.Compat.type => Boolean)test.Compat.type` +[accessible: true] `method ensuring(cond: test.Compat.type => Boolean, msg: => Any)test.Compat.type` +[accessible: true] `method eq(x$1: AnyRef)Boolean` +[accessible: true] `method equals(x$1: Any)Boolean` +[accessible: true] `method formatted(fmtstr: String)String` +[accessible: true] `method hashCode()Int` +[accessible: true] `method isInstanceOf[T0]=> Boolean` +[accessible: true] `method ne(x$1: AnyRef)Boolean` +[accessible: true] `method notify()Unit` +[accessible: true] `method notifyAll()Unit` +[accessible: true] `method synchronized[T0](x$1: T0)T0` +[accessible: true] `method toString()String` +[accessible: true] `method wait()Unit` +[accessible: true] `method wait(x$1: Long)Unit` +[accessible: true] `method wait(x$1: Long, x$2: Int)Unit` +[accessible: true] `method x=> test.Compat.type` +[accessible: true] `method →[B](y: B)(test.Compat.type, B)` +[accessible: true] `lazy value fooInt` +[accessible: false] `method clone()Object` +[accessible: false] `method finalize()Unit` +[accessible: true] `value CONST_STRINGString("constant")` +[accessible: false] `value __leftOfArrowtest.Compat.type` +[accessible: false] `value __resultOfEnsuringtest.Compat.type` +[accessible: false] `value selfAny` +================================================================================ + +askTypeCompletion at Completions.scala(10,9) +================================================================================ +[response] aksTypeCompletion at (10,9) +retrieved 38 members +[accessible: true] `method !=(x$1: Any)Boolean` +[accessible: true] `method !=(x$1: AnyRef)Boolean` +[accessible: true] `method ##()Int` +[accessible: true] `method +(other: String)String` +[accessible: true] `method ->[B](y: B)(test.Compat.type, B)` +[accessible: true] `method ==(x$1: Any)Boolean` +[accessible: true] `method ==(x$1: AnyRef)Boolean` +[accessible: true] `method asInstanceOf[T0]=> T0` +[accessible: true] `method ensuring(cond: Boolean)test.Compat.type` +[accessible: true] `method ensuring(cond: Boolean, msg: => Any)test.Compat.type` +[accessible: true] `method ensuring(cond: test.Compat.type => Boolean)test.Compat.type` +[accessible: true] `method ensuring(cond: test.Compat.type => Boolean, msg: => Any)test.Compat.type` +[accessible: true] `method eq(x$1: AnyRef)Boolean` +[accessible: true] `method equals(x$1: Any)Boolean` +[accessible: true] `method formatted(fmtstr: String)String` +[accessible: true] `method hashCode()Int` +[accessible: true] `method isInstanceOf[T0]=> Boolean` +[accessible: true] `method ne(x$1: AnyRef)Boolean` +[accessible: true] `method notify()Unit` +[accessible: true] `method notifyAll()Unit` +[accessible: true] `method synchronized[T0](x$1: T0)T0` +[accessible: true] `method toString()String` +[accessible: true] `method wait()Unit` +[accessible: true] `method wait(x$1: Long)Unit` +[accessible: true] `method wait(x$1: Long, x$2: Int)Unit` +[accessible: true] `method x=> test.Compat.type` +[accessible: true] `method →[B](y: B)(test.Compat.type, B)` +[accessible: true] `lazy value fooInt` +[accessible: false] `method clone()Object` +[accessible: false] `method finalize()Unit` +[accessible: true] `value CONST_STRINGString("constant")` +[accessible: false] `value __leftOfArrowtest.Compat.type` +[accessible: false] `value __resultOfEnsuringtest.Compat.type` +[accessible: false] `value selfAny` +================================================================================ diff --git a/test/pending/presentation/t5708/Test.scala b/test/pending/presentation/t5708/Test.scala new file mode 100644 index 0000000000..96e758d974 --- /dev/null +++ b/test/pending/presentation/t5708/Test.scala @@ -0,0 +1,5 @@ +import scala.tools.nsc.interactive.tests.InteractiveTest + +object Test extends InteractiveTest { + +}
\ No newline at end of file diff --git a/test/pending/presentation/t5708/src/Completions.scala b/test/pending/presentation/t5708/src/Completions.scala new file mode 100644 index 0000000000..cc41492df7 --- /dev/null +++ b/test/pending/presentation/t5708/src/Completions.scala @@ -0,0 +1,11 @@ +package test + +object Compat { + final val CONST_STRING = "constant" + lazy val foo = 4 +} + +class Foo { + Compat./*!*/CONST_STRING // its 'accessible' flag is false + Compat./*!*/foo // its 'accessible' flag is false +} diff --git a/test/pending/run/t4560.scala b/test/pending/run/t4560.scala new file mode 100644 index 0000000000..fe62136319 --- /dev/null +++ b/test/pending/run/t4560.scala @@ -0,0 +1,9 @@ +trait B { + this: Test.type => + + def y = new { def f() = () } + def fail() = y.f() +} +object Test extends B { + def main(args: Array[String]): Unit = fail() +}
\ No newline at end of file diff --git a/test/pending/run/t4728.check b/test/pending/run/t4728.check new file mode 100644 index 0000000000..7a754f414c --- /dev/null +++ b/test/pending/run/t4728.check @@ -0,0 +1,2 @@ +1 +2
\ No newline at end of file diff --git a/test/pending/run/t4728.scala b/test/pending/run/t4728.scala new file mode 100644 index 0000000000..36f7860613 --- /dev/null +++ b/test/pending/run/t4728.scala @@ -0,0 +1,11 @@ +class X +class Y extends X +object Ambiguous { + def f(x: X) = 1 + def f(ys: Y*) = 2 +} + +object Test extends App { + println(Ambiguous.f(new X)) + println(Ambiguous.f(new Y)) +}
\ No newline at end of file diff --git a/test/pending/run/t5610a.check b/test/pending/run/t5610a.check new file mode 100644 index 0000000000..2aa46b3b91 --- /dev/null +++ b/test/pending/run/t5610a.check @@ -0,0 +1 @@ +Stroke a kitten diff --git a/test/pending/run/t5610a.scala b/test/pending/run/t5610a.scala new file mode 100644 index 0000000000..f20b295762 --- /dev/null +++ b/test/pending/run/t5610a.scala @@ -0,0 +1,19 @@ +object Test extends App { + class Result(_str: => String) { + lazy val str = _str + } + + def foo(str: => String)(i: Int) = new Result(str) + + def bar(f: Int => Result) = f(42) + + var test: String = null + val result = bar(foo(test)) + test = "bar" + + if (result.str == null) { + println("Destroy ALL THE THINGS!!!") + } else { + println("Stroke a kitten") + } +}
\ No newline at end of file diff --git a/test/pending/run/t5610b.check b/test/pending/run/t5610b.check new file mode 100644 index 0000000000..2aa46b3b91 --- /dev/null +++ b/test/pending/run/t5610b.check @@ -0,0 +1 @@ +Stroke a kitten diff --git a/test/pending/run/t5610b.scala b/test/pending/run/t5610b.scala new file mode 100644 index 0000000000..d922d6333c --- /dev/null +++ b/test/pending/run/t5610b.scala @@ -0,0 +1,21 @@ +object Bug { + def main(args: Array[String]) { + var test: String = null + val result = bar(foo(test)) + test = "bar" + + if (result.str == null) { + println("Destroy ALL THE THINGS!!!") + } else { + println("Stroke a kitten") + } + } + + class Result(_str: => String) { + lazy val str = _str + } + + def foo(str: => String)(i: Int) = new Result(str) + + def bar(f: Int => Result) = f(42) +}
\ No newline at end of file diff --git a/test/pending/run/t5695.check b/test/pending/run/t5695.check new file mode 100644 index 0000000000..d50069ab4f --- /dev/null +++ b/test/pending/run/t5695.check @@ -0,0 +1,2 @@ +.. +.. diff --git a/test/pending/run/t5695/part_1.scala b/test/pending/run/t5695/part_1.scala new file mode 100644 index 0000000000..b8e8f8e52f --- /dev/null +++ b/test/pending/run/t5695/part_1.scala @@ -0,0 +1,12 @@ +import language.experimental.macros +import scala.reflect.makro.Context + +object Defs { + + def mkInt = macro mkIntImpl + def mkIntImpl(c: Context): c.Expr[Any] = { + println(c.enclosingApplication) + c.reify{ 23 } + } + +} diff --git a/test/pending/run/t5695/part_2.scala b/test/pending/run/t5695/part_2.scala new file mode 100644 index 0000000000..d34219437d --- /dev/null +++ b/test/pending/run/t5695/part_2.scala @@ -0,0 +1,8 @@ +import Defs._ + +object Test extends App { + + val i1 = mkInt + val i2 = identity(mkInt) + +} diff --git a/test/pending/run/t5726a.scala b/test/pending/run/t5726a.scala new file mode 100644 index 0000000000..24d828a159 --- /dev/null +++ b/test/pending/run/t5726a.scala @@ -0,0 +1,17 @@ +import language.dynamics + +class DynamicTest extends Dynamic { + def selectDynamic(name: String) = s"value of $name" + def updateDynamic(name: String)(value: Any) { + println(s"You have just updated property '$name' with value: $value") + } +} + +object MyApp extends App { + def testing() { + val test = new DynamicTest + test.firstName = "John" + } + + testing() +}
\ No newline at end of file diff --git a/test/pending/run/t5726b.scala b/test/pending/run/t5726b.scala new file mode 100644 index 0000000000..839dcf40b5 --- /dev/null +++ b/test/pending/run/t5726b.scala @@ -0,0 +1,16 @@ +import language.dynamics + +class DynamicTest extends Dynamic { + def updateDynamic(name: String)(value: Any) { + println(s"You have just updated property '$name' with value: $value") + } +} + +object MyApp extends App { + def testing() { + val test = new DynamicTest + test.firstName = "John" + } + + testing() +}
\ No newline at end of file |