From 990b3c7682d9b0655518e20274673aade75dbed0 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Mon, 17 Sep 2012 13:45:43 +0200 Subject: SI-6380 #1 Add @throws[Exception] This change allows an additional notation of the @throws annotation: Old-style: @throws(classOf[Exception]) New-style: @throws[Exception] The optional String argument moves @throws in line with @deprecated, @migration, etc. and prevents confusion caused by the default inheritance of ScalaDoc comments and the non-inheritance of annotations. Before: /** This method does ... * @throws IllegalArgumentException if `a` is less than 0. */ @throws(classOf[IllegalArgumentException]) def foo(a: Int) = ... Now: /** This method does ... */ @throws[IllegalArgumentException]("if `a` is less than 0") def foo(a: Int) = ... ScalaDoc @throws tags remain supported for cases where documentation of thrown exceptions is needed, but are not supposed to be added to the exception attribute of the class file. In this commit the necessary compiler support is added. The code to extract exceptions from annotations is now shared instead of being duplicated all over the place. The change is completely source and binary compatible, except that the code is now enforcing that the type thrown is a subtype of Throwable as mandated by the JVM spec instead of allowing something like @throws(classOf[String]). Not in this commit: - ScalaDoc support to add the String argument to ScalaDoc's exception list - Adaption of the library --- test/files/run/t6380.check | 7 +++++++ test/files/run/t6380.scala | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/files/run/t6380.check create mode 100644 test/files/run/t6380.scala (limited to 'test') diff --git a/test/files/run/t6380.check b/test/files/run/t6380.check new file mode 100644 index 0000000000..912525ed66 --- /dev/null +++ b/test/files/run/t6380.check @@ -0,0 +1,7 @@ +List(class java.lang.Exception) +List(class java.lang.Throwable) +List(class java.lang.RuntimeException) +List(class java.lang.IllegalArgumentException, class java.util.NoSuchElementException) +List(class java.lang.IndexOutOfBoundsException, class java.lang.IndexOutOfBoundsException) +List(class java.lang.IllegalStateException, class java.lang.IllegalStateException) +List(class java.lang.NullPointerException, class java.lang.NullPointerException) diff --git a/test/files/run/t6380.scala b/test/files/run/t6380.scala new file mode 100644 index 0000000000..0e264d9175 --- /dev/null +++ b/test/files/run/t6380.scala @@ -0,0 +1,20 @@ +object Test extends App { + classOf[Foo].getDeclaredMethods().sortBy(_.getName).map(_.getExceptionTypes.sortBy(_.getName).toList).toList.foreach(println) +} + +class Foo { + @throws[Exception] + def bar1 = ??? + @throws[Throwable]("always") + def bar2 = ??? + @throws(classOf[RuntimeException]) + def bar3 = ??? + @throws[IllegalArgumentException] @throws[NoSuchElementException] + def bar4 = ??? + @throws(classOf[IndexOutOfBoundsException]) @throws(classOf[IndexOutOfBoundsException]) + def bar5 = ??? + @throws[IllegalStateException]("Cause") @throws[IllegalStateException] + def bar6 = ??? + @throws[NullPointerException]("Cause A") @throws[NullPointerException]("Cause B") + def bar7 = ??? +} \ No newline at end of file -- cgit v1.2.3 From 4e87654a9187fc65e5971580f4e25589fff052b9 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sun, 23 Sep 2012 14:04:40 +0200 Subject: showRaw no longer crashes on NoSymbol --- src/reflect/scala/reflect/internal/Printers.scala | 3 ++- test/files/run/showraw_nosymbol.check | 1 + test/files/run/showraw_nosymbol.scala | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/files/run/showraw_nosymbol.check create mode 100644 test/files/run/showraw_nosymbol.scala (limited to 'test') diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala index cb8dc4b197..fb165ab50f 100644 --- a/src/reflect/scala/reflect/internal/Printers.scala +++ b/src/reflect/scala/reflect/internal/Printers.scala @@ -576,7 +576,8 @@ trait Printers extends api.Printers { self: SymbolTable => case _ => // do nothing }) case sym: Symbol => - if (sym.isStatic && (sym.isClass || sym.isModule)) print(sym.fullName) + if (sym == NoSymbol) print("NoSymbol") + else if (sym.isStatic && (sym.isClass || sym.isModule)) print(sym.fullName) else print(sym.name) if (printIds) print("#", sym.id) if (printKinds) print("#", sym.abbreviatedKindString) diff --git a/test/files/run/showraw_nosymbol.check b/test/files/run/showraw_nosymbol.check new file mode 100644 index 0000000000..c54fe74717 --- /dev/null +++ b/test/files/run/showraw_nosymbol.check @@ -0,0 +1 @@ +NoSymbol diff --git a/test/files/run/showraw_nosymbol.scala b/test/files/run/showraw_nosymbol.scala new file mode 100644 index 0000000000..fbdc1591c9 --- /dev/null +++ b/test/files/run/showraw_nosymbol.scala @@ -0,0 +1,5 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + println(showRaw(NoSymbol)) +} \ No newline at end of file -- cgit v1.2.3 From a6b81ac12a45866e97d30133c12dee775b93ea39 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sun, 23 Sep 2012 14:07:22 +0200 Subject: SI-6417 correctly reifies non-value types If we're reifying non-value types (e.g. MethodTypes), we can't use them as type arguments for TypeTag/WeakTypeTag factory methods, otherwise the macro expansion won't typecheck: http://groups.google.com/group/scala-internals/browse_thread/thread/2d7bb85bfcdb2e2 This situation is impossible if one uses only reify and type tags, but c.reifyTree and c.reifyType exposes in the macro API let anyone feed anything into the reifier. Therefore I now check the tpe that is about to be used in TypeApply wrapping TypeTag/WeakTypeTag factory methods and replace it with AnyTpe if it doesn't fit. --- .../scala/reflect/reify/utils/Extractors.scala | 14 ++++++++--- test/files/run/macro-reify-type.check | 1 + test/files/run/macro-reify-type.flags | 1 + test/files/run/macro-reify-type/Macros_1.scala | 27 ++++++++++++++++++++++ test/files/run/macro-reify-type/Test_2.scala | 21 +++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/files/run/macro-reify-type.check create mode 100644 test/files/run/macro-reify-type.flags create mode 100644 test/files/run/macro-reify-type/Macros_1.scala create mode 100644 test/files/run/macro-reify-type/Test_2.scala (limited to 'test') diff --git a/src/compiler/scala/reflect/reify/utils/Extractors.scala b/src/compiler/scala/reflect/reify/utils/Extractors.scala index b7206eda0e..523520749b 100644 --- a/src/compiler/scala/reflect/reify/utils/Extractors.scala +++ b/src/compiler/scala/reflect/reify/utils/Extractors.scala @@ -92,11 +92,19 @@ trait Extractors { Block(List(universeAlias, mirrorAlias), wrappee) } + private def mkTarg(tpe: Type): Tree = { + // if we're reifying a MethodType, we can't use it as a type argument for TypeTag ctor + // http://groups.google.com/group/scala-internals/browse_thread/thread/2d7bb85bfcdb2e2 + val guineaPig = Apply(TypeApply(Select(Select(gen.mkRuntimeUniverseRef, nme.TypeTag), nme.apply), List(TypeTree(tpe))), List(Literal(Constant(null)), Literal(Constant(null)))) + val isGoodTpe = typer.silent(_.typed(guineaPig)) match { case analyzer.SilentResultValue(_) => true; case _ => false } + TypeTree(if (isGoodTpe) tpe else AnyTpe) + } + object ReifiedTree { def apply(universe: Tree, mirror: Tree, symtab: SymbolTable, rtree: Tree, tpe: Type, rtpe: Tree, concrete: Boolean): Tree = { val tagFactory = if (concrete) nme.TypeTag else nme.WeakTypeTag - val tagCtor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), tagFactory), nme.apply), List(TypeTree(tpe))) - val exprCtor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), nme.Expr), nme.apply), List(TypeTree(tpe))) + val tagCtor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), tagFactory), nme.apply), List(mkTarg(tpe))) + val exprCtor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), nme.Expr), nme.apply), List(mkTarg(tpe))) val tagArgs = List(Ident(nme.MIRROR_SHORT), mkCreator(tpnme.REIFY_TYPECREATOR_PREFIX, symtab, rtpe)) val unwrapped = Apply(Apply(exprCtor, List(Ident(nme.MIRROR_SHORT), mkCreator(tpnme.REIFY_TREECREATOR_PREFIX, symtab, rtree))), List(Apply(tagCtor, tagArgs))) mkWrapper(universe, mirror, unwrapped) @@ -123,7 +131,7 @@ trait Extractors { object ReifiedType { def apply(universe: Tree, mirror: Tree, symtab: SymbolTable, tpe: Type, rtpe: Tree, concrete: Boolean) = { val tagFactory = if (concrete) nme.TypeTag else nme.WeakTypeTag - val ctor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), tagFactory), nme.apply), List(TypeTree(tpe))) + val ctor = TypeApply(Select(Select(Ident(nme.UNIVERSE_SHORT), tagFactory), nme.apply), List(mkTarg(tpe))) val args = List(Ident(nme.MIRROR_SHORT), mkCreator(tpnme.REIFY_TYPECREATOR_PREFIX, symtab, rtpe)) val unwrapped = Apply(ctor, args) mkWrapper(universe, mirror, unwrapped) diff --git a/test/files/run/macro-reify-type.check b/test/files/run/macro-reify-type.check new file mode 100644 index 0000000000..ea5e70e10d --- /dev/null +++ b/test/files/run/macro-reify-type.check @@ -0,0 +1 @@ +[B, That](f: Int => B)(implicit bf: scala.collection.generic.CanBuildFrom[List[Int],B,That])That \ No newline at end of file diff --git a/test/files/run/macro-reify-type.flags b/test/files/run/macro-reify-type.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/run/macro-reify-type.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/test/files/run/macro-reify-type/Macros_1.scala b/test/files/run/macro-reify-type/Macros_1.scala new file mode 100644 index 0000000000..aeec9fc97c --- /dev/null +++ b/test/files/run/macro-reify-type/Macros_1.scala @@ -0,0 +1,27 @@ +import scala.reflect.macros.Context +import scala.reflect.runtime.{universe => ru} + +object StaticReflect { + def method[A](name: String): ru.Type = macro methodImpl[A] + + def methodImpl[A: c.WeakTypeTag](c: Context)(name: c.Expr[String]): c.Expr[ru.Type] = { + import c.universe._ + + val nameName: TermName = name.tree match { + case Literal(Constant(str: String)) => newTermName(str) + case _ => c.error(c.enclosingPosition, s"Method name not constant.") ; return reify(ru.NoType) + } + val clazz = weakTypeOf[A] + + clazz member nameName match { + case NoSymbol => c.error(c.enclosingPosition, s"No member called $nameName in $clazz.") ; reify(ru.NoType) + case member => + val mtpe = member typeSignatureIn clazz + val mtag = c.reifyType(c.runtimeUniverse, Select(c.runtimeUniverse, newTermName("rootMirror")), mtpe) + val mtree = Select(mtag, newTermName("tpe")) + + c.Expr[ru.Type](mtree) + } + } + +} diff --git a/test/files/run/macro-reify-type/Test_2.scala b/test/files/run/macro-reify-type/Test_2.scala new file mode 100644 index 0000000000..9beaf98681 --- /dev/null +++ b/test/files/run/macro-reify-type/Test_2.scala @@ -0,0 +1,21 @@ +import StaticReflect._ + +object Test extends App { + //println(method[List[Int]]("distinct")) + println(method[List[Int]]("map")) + //val $u: scala.reflect.runtime.universe.type = scala.reflect.runtime.universe; + //val $m: $u.Mirror = scala.reflect.runtime.universe.rootMirror; + //import $u._, $m._, Flag._ + //val tpe = { + // val symdef$B2 = build.newNestedSymbol(build.selectTerm(staticClass("scala.collection.TraversableLike"), "map"), newTypeName("B"), NoPosition, DEFERRED | PARAM, false); + // val symdef$That2 = build.newNestedSymbol(build.selectTerm(staticClass("scala.collection.TraversableLike"), "map"), newTypeName("That"), NoPosition, DEFERRED | PARAM, false); + // val symdef$f2 = build.newNestedSymbol(build.selectTerm(staticClass("scala.collection.TraversableLike"), "map"), newTermName("f"), NoPosition, PARAM, false); + // val symdef$bf2 = build.newNestedSymbol(build.selectTerm(staticClass("scala.collection.TraversableLike"), "map"), newTermName("bf"), NoPosition, IMPLICIT | PARAM, false); + // build.setTypeSignature(symdef$B2, TypeBounds(staticClass("scala.Nothing").asType.toTypeConstructor, staticClass("scala.Any").asType.toTypeConstructor)); + // build.setTypeSignature(symdef$That2, TypeBounds(staticClass("scala.Nothing").asType.toTypeConstructor, staticClass("scala.Any").asType.toTypeConstructor)); + // build.setTypeSignature(symdef$f2, TypeRef(ThisType(staticPackage("scala").asModule.moduleClass), staticClass("scala.Function1"), List(staticClass("scala.Int").asType.toTypeConstructor, TypeRef(NoPrefix, symdef$B2, List())))); + // build.setTypeSignature(symdef$bf2, TypeRef(ThisType(staticPackage("scala.collection.generic").asModule.moduleClass), staticClass("scala.collection.generic.CanBuildFrom"), List(TypeRef(ThisType(staticPackage("scala.collection.immutable").asModule.moduleClass), staticClass("scala.collection.immutable.List"), List(staticClass("scala.Int").asType.toTypeConstructor)), TypeRef(NoPrefix, symdef$B2, List()), TypeRef(NoPrefix, symdef$That2, List())))); + // PolyType(List(symdef$B2, symdef$That2), MethodType(List(symdef$f2), MethodType(List(symdef$bf2), TypeRef(NoPrefix, symdef$That2, List())))) + //} + //println(tpe) +} \ No newline at end of file -- cgit v1.2.3 From b5b614444cefe84861b06a09fbaf10d100556556 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 27 Sep 2012 16:12:50 -0700 Subject: Implementations of isValueType and isNonValueType. Restrictions regarding how non-value types can be used have generally not been enforced explicitly, depending instead on the fact that the compiler wouldn't attempt to use them in strange ways like offering a method type as a type argument. Since users can now create most types from scratch, it has become important to enforce the restrictions in a more direct fashion. This was a lot harder than it probably should have been because there are so many types which go unmentioned by the specification. Hopefully a useful exercise in any case. --- .../scala/reflect/reify/utils/Extractors.scala | 13 ++- src/reflect/scala/reflect/internal/Types.scala | 116 ++++++++++++++++++++- test/files/run/fail-non-value-types.check | 2 + test/files/run/fail-non-value-types.scala | 30 ++++++ test/files/run/macro-reify-type/Macros_1.scala | 2 +- 5 files changed, 150 insertions(+), 13 deletions(-) create mode 100644 test/files/run/fail-non-value-types.check create mode 100644 test/files/run/fail-non-value-types.scala (limited to 'test') diff --git a/src/compiler/scala/reflect/reify/utils/Extractors.scala b/src/compiler/scala/reflect/reify/utils/Extractors.scala index 523520749b..b60d15c1d4 100644 --- a/src/compiler/scala/reflect/reify/utils/Extractors.scala +++ b/src/compiler/scala/reflect/reify/utils/Extractors.scala @@ -92,13 +92,12 @@ trait Extractors { Block(List(universeAlias, mirrorAlias), wrappee) } - private def mkTarg(tpe: Type): Tree = { - // if we're reifying a MethodType, we can't use it as a type argument for TypeTag ctor - // http://groups.google.com/group/scala-internals/browse_thread/thread/2d7bb85bfcdb2e2 - val guineaPig = Apply(TypeApply(Select(Select(gen.mkRuntimeUniverseRef, nme.TypeTag), nme.apply), List(TypeTree(tpe))), List(Literal(Constant(null)), Literal(Constant(null)))) - val isGoodTpe = typer.silent(_.typed(guineaPig)) match { case analyzer.SilentResultValue(_) => true; case _ => false } - TypeTree(if (isGoodTpe) tpe else AnyTpe) - } + // if we're reifying a MethodType, we can't use it as a type argument for TypeTag ctor + // http://groups.google.com/group/scala-internals/browse_thread/thread/2d7bb85bfcdb2e2 + private def mkTarg(tpe: Type): Tree = ( + if ((tpe eq null) || !isUseableAsTypeArg(tpe)) TypeTree(AnyTpe) + else TypeTree(tpe) + ) object ReifiedTree { def apply(universe: Tree, mirror: Tree, symtab: SymbolTable, rtree: Tree, tpe: Type, rtpe: Tree, concrete: Boolean): Tree = { diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 6b274467fc..0e8665ee84 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -66,9 +66,9 @@ import util.ThreeValues._ // a type variable // Replace occurrences of type parameters with type vars, where // inst is the instantiation and constr is a list of bounds. - case DeBruijnIndex(level, index) + case DeBruijnIndex(level, index, args) // for dependent method types: a type referring to a method parameter. - case ErasedValueType(clazz, underlying) + case ErasedValueType(tref) // only used during erasure of derived value classes. */ @@ -3623,9 +3623,20 @@ trait Types extends api.Types { self: SymbolTable => */ /** A creator for type applications */ - def appliedType(tycon: Type, args: List[Type]): Type = - if (args.isEmpty) tycon //@M! `if (args.isEmpty) tycon' is crucial (otherwise we create new types in phases after typer and then they don't get adapted (??)) - else tycon match { + def appliedType(tycon: Type, args: List[Type]): Type = { + if (args.isEmpty) + return tycon //@M! `if (args.isEmpty) tycon' is crucial (otherwise we create new types in phases after typer and then they don't get adapted (??)) + + /** Disabled - causes cycles in tcpoly tests. */ + if (false && isDefinitionsInitialized) { + assert(isUseableAsTypeArgs(args), { + val tapp_s = s"""$tycon[${args mkString ", "}]""" + val arg_s = args filterNot isUseableAsTypeArg map (t => t + "/" + t.getClass) mkString ", " + s"$tapp_s includes illegal type argument $arg_s" + }) + } + + tycon match { case TypeRef(pre, sym @ (NothingClass|AnyClass), _) => copyTypeRef(tycon, pre, sym, Nil) //@M drop type args to Any/Nothing case TypeRef(pre, sym, _) => copyTypeRef(tycon, pre, sym, args) case PolyType(tparams, restpe) => restpe.instantiateTypeParams(tparams, args) @@ -3639,6 +3650,7 @@ trait Types extends api.Types { self: SymbolTable => case WildcardType => tycon // needed for neg/t0226 case _ => abort(debugString(tycon)) } + } /** Very convenient. */ def appliedType(tyconSym: Symbol, args: Type*): Type = @@ -5732,6 +5744,100 @@ trait Types extends api.Types { self: SymbolTable => case _ => false } + /** This is defined and named as it is because the goal is to exclude source + * level types which are not value types (e.g. MethodType) without excluding + * necessary internal types such as WildcardType. There are also non-value + * types which can be used as type arguments (e.g. type constructors.) + */ + def isUseableAsTypeArg(tp: Type) = ( + isInternalTypeUsedAsTypeArg(tp) // the subset of internal types which can be type args + || isHKTypeRef(tp) // not a value type, but ok as a type arg + || isValueElseNonValue(tp) // otherwise only value types + ) + + private def isHKTypeRef(tp: Type) = tp match { + case TypeRef(_, sym, Nil) => tp.isHigherKinded + case _ => false + } + @tailrec final def isUseableAsTypeArgs(tps: List[Type]): Boolean = tps match { + case Nil => true + case x :: xs => isUseableAsTypeArg(x) && isUseableAsTypeArgs(xs) + } + + /** The "third way", types which are neither value types nor + * non-value types as defined in the SLS, further divided into + * types which are used internally in type applications and + * types which are not. + */ + private def isInternalTypeNotUsedAsTypeArg(tp: Type): Boolean = tp match { + case AntiPolyType(pre, targs) => true + case ClassInfoType(parents, defs, clazz) => true + case DeBruijnIndex(level, index, args) => true + case ErasedValueType(tref) => true + case NoPrefix => true + case NoType => true + case SuperType(thistpe, supertpe) => true + case TypeBounds(lo, hi) => true + case _ => false + } + private def isInternalTypeUsedAsTypeArg(tp: Type): Boolean = tp match { + case WildcardType => true + case BoundedWildcardType(_) => true + case ErrorType => true + case _: TypeVar => true + case _ => false + } + private def isAlwaysValueType(tp: Type) = tp match { + case RefinedType(_, _) => true + case ExistentialType(_, _) => true + case ConstantType(_) => true + case _ => false + } + private def isAlwaysNonValueType(tp: Type) = tp match { + case OverloadedType(_, _) => true + case NullaryMethodType(_) => true + case MethodType(_, _) => true + case PolyType(_, MethodType(_, _)) => true + case _ => false + } + /** Should be called only with types for which a clear true/false answer + * can be given: true == value type, false == non-value type. Otherwise, + * an exception is thrown. + */ + private def isValueElseNonValue(tp: Type): Boolean = tp match { + case tp if isAlwaysValueType(tp) => true + case tp if isAlwaysNonValueType(tp) => false + case AnnotatedType(_, underlying, _) => isValueElseNonValue(underlying) + case SingleType(_, sym) => sym.isValue // excludes packages and statics + case TypeRef(_, _, _) if tp.isHigherKinded => false // excludes type constructors + case ThisType(sym) => !sym.isPackageClass // excludes packages + case TypeRef(_, sym, _) => !sym.isPackageClass // excludes packages + case PolyType(_, _) => true // poly-methods excluded earlier + case tp => sys.error("isValueElseNonValue called with third-way type " + tp) + } + + /** SLS 3.2, Value Types + * Is the given type definitely a value type? A true result means + * it verifiably is, but a false result does not mean it is not, + * only that it cannot be assured. To avoid false positives, this + * defaults to false, but since Type is not sealed, one should take + * a false answer with a grain of salt. This method may be primarily + * useful as documentation; it is likely that !isNonValueType(tp) + * will serve better than isValueType(tp). + */ + def isValueType(tp: Type) = isValueElseNonValue(tp) + + /** SLS 3.3, Non-Value Types + * Is the given type definitely a non-value type, as defined in SLS 3.3? + * The specification-enumerated non-value types are method types, polymorphic + * method types, and type constructors. Supplements to the specified set of + * non-value types include: types which wrap non-value symbols (packages + * abd statics), overloaded types. Varargs and by-name types T* and (=>T) are + * not designated non-value types because there is code which depends on using + * them as type arguments, but their precise status is unclear. + */ + def isNonValueType(tp: Type) = !isValueElseNonValue(tp) + def isNonRefinementClassType(tpe: Type) = tpe match { case SingleType(_, sym) => sym.isModuleClass case TypeRef(_, sym, _) => sym.isClass && !sym.isRefinementClass diff --git a/test/files/run/fail-non-value-types.check b/test/files/run/fail-non-value-types.check new file mode 100644 index 0000000000..1c2d7dcf1b --- /dev/null +++ b/test/files/run/fail-non-value-types.check @@ -0,0 +1,2 @@ +[B, That](f: A => B)(implicit cbf: ImaginaryCanBuildFrom[CompletelyIndependentList.this.Repr,B,That])That +()CompletelyIndependentList[A] diff --git a/test/files/run/fail-non-value-types.scala b/test/files/run/fail-non-value-types.scala new file mode 100644 index 0000000000..d9aa5c01ca --- /dev/null +++ b/test/files/run/fail-non-value-types.scala @@ -0,0 +1,30 @@ +import scala.reflect.runtime.universe._ + +class ImaginaryCanBuildFrom[-From, -Elem, +To] +class CompletelyIndependentList[+A] { + type Repr <: CompletelyIndependentList[A] + def map[B, That](f: A => B)(implicit cbf: ImaginaryCanBuildFrom[Repr, B, That]): That = ??? + def distinct(): CompletelyIndependentList[A] = ??? +} + +object Test { + var failed = false + def expectFailure[T](body: => T): Boolean = { + try { val res = body ; failed = true ; println(res + " failed to fail.") ; false } + catch { case _: AssertionError => true } + } + + /** Attempt to use a method type as a type argument - expect failure. */ + def tcon[T: TypeTag](args: Type*) = appliedType(typeOf[T].typeConstructor, args.toList) + + val map = typeOf[CompletelyIndependentList[Int]].member("map": TermName).typeSignature + val distinct = typeOf[CompletelyIndependentList[Int]].member("distinct": TermName).typeSignature + + def main(args: Array[String]): Unit = { + expectFailure(println(tcon[CompletelyIndependentList[Int]](map))) + expectFailure(tcon[CompletelyIndependentList[Int]](distinct)) + println(map) + println(distinct) + if (failed) sys.exit(1) + } +} diff --git a/test/files/run/macro-reify-type/Macros_1.scala b/test/files/run/macro-reify-type/Macros_1.scala index aeec9fc97c..06de05735d 100644 --- a/test/files/run/macro-reify-type/Macros_1.scala +++ b/test/files/run/macro-reify-type/Macros_1.scala @@ -17,7 +17,7 @@ object StaticReflect { case NoSymbol => c.error(c.enclosingPosition, s"No member called $nameName in $clazz.") ; reify(ru.NoType) case member => val mtpe = member typeSignatureIn clazz - val mtag = c.reifyType(c.runtimeUniverse, Select(c.runtimeUniverse, newTermName("rootMirror")), mtpe) + val mtag = c.reifyType(treeBuild.mkRuntimeUniverseRef, Select(treeBuild.mkRuntimeUniverseRef, newTermName("rootMirror")), mtpe) val mtree = Select(mtag, newTermName("tpe")) c.Expr[ru.Type](mtree) -- cgit v1.2.3 From e55e164e9335b0e725ebd679a66adf368d1482e0 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 27 Sep 2012 18:52:19 -0700 Subject: Fix for failing test. There's some very sketchy behavior visible - I'm printing a method signature and getting this: [B <: , That <: ](f: )(implicit cbf: )That But there's no exposed way to force the info. Am I supposed to call isSealed or something? --- test/files/run/fail-non-value-types.check | 3 ++- test/files/run/fail-non-value-types.scala | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/files/run/fail-non-value-types.check b/test/files/run/fail-non-value-types.check index 1c2d7dcf1b..4e80a11420 100644 --- a/test/files/run/fail-non-value-types.check +++ b/test/files/run/fail-non-value-types.check @@ -1,2 +1,3 @@ -[B, That](f: A => B)(implicit cbf: ImaginaryCanBuildFrom[CompletelyIndependentList.this.Repr,B,That])That +[B <: , That <: ](f: )(implicit cbf: )That +[B, That](f: Int => B)(implicit cbf: ImaginaryCanBuildFrom[CompletelyIndependentList[Int]#Repr,B,That])That ()CompletelyIndependentList[A] diff --git a/test/files/run/fail-non-value-types.scala b/test/files/run/fail-non-value-types.scala index d9aa5c01ca..51198a5f31 100644 --- a/test/files/run/fail-non-value-types.scala +++ b/test/files/run/fail-non-value-types.scala @@ -17,14 +17,24 @@ object Test { /** Attempt to use a method type as a type argument - expect failure. */ def tcon[T: TypeTag](args: Type*) = appliedType(typeOf[T].typeConstructor, args.toList) - val map = typeOf[CompletelyIndependentList[Int]].member("map": TermName).typeSignature - val distinct = typeOf[CompletelyIndependentList[Int]].member("distinct": TermName).typeSignature + def cil = typeOf[CompletelyIndependentList[Int]] + def map = cil.member("map": TermName).asMethod + def distinct = cil.member("distinct": TermName).asMethod def main(args: Array[String]): Unit = { - expectFailure(println(tcon[CompletelyIndependentList[Int]](map))) - expectFailure(tcon[CompletelyIndependentList[Int]](distinct)) - println(map) - println(distinct) + // Need the assert in there to fail. + // expectFailure(println(tcon[CompletelyIndependentList[Int]](map))) + // expectFailure(tcon[CompletelyIndependentList[Int]](distinct)) + + // Why is the first map signature printing showing an + // uninitialized symbol? + // + // [B <: , That <: ](f: )(implicit cbf: )That + // + + println(map.typeSignature) + println(map.typeSignatureIn(cil)) + println(distinct.typeSignature) if (failed) sys.exit(1) } } -- cgit v1.2.3 From c395c926216b4356c82c606b76784a184a7f1d9b Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 28 Sep 2012 14:20:27 +0200 Subject: fully initializes symbols on `typeSignature` only affects runtime reflection, because Symbol.typeSignature is only defined in the reflection API. the rest of the compiler uses Symbol.info instead. --- src/reflect/scala/reflect/internal/Symbols.scala | 4 ++-- test/files/run/fail-non-value-types.check | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index 21506a498d..d387ad764d 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -91,8 +91,8 @@ trait Symbols extends api.Symbols { self: SymbolTable => def module = sourceModule def thisPrefix: Type = thisType def selfType: Type = typeOfThis - def typeSignature: Type = info - def typeSignatureIn(site: Type): Type = site memberInfo this + def typeSignature: Type = { fullyInitializeSymbol(this); info } + def typeSignatureIn(site: Type): Type = { fullyInitializeSymbol(this); site memberInfo this } def toType: Type = tpe def toTypeIn(site: Type): Type = site.memberType(this) diff --git a/test/files/run/fail-non-value-types.check b/test/files/run/fail-non-value-types.check index 4e80a11420..714dce2c50 100644 --- a/test/files/run/fail-non-value-types.check +++ b/test/files/run/fail-non-value-types.check @@ -1,3 +1,3 @@ -[B <: , That <: ](f: )(implicit cbf: )That +[B, That](f: A => B)(implicit cbf: ImaginaryCanBuildFrom[CompletelyIndependentList.this.Repr,B,That])That [B, That](f: Int => B)(implicit cbf: ImaginaryCanBuildFrom[CompletelyIndependentList[Int]#Repr,B,That])That ()CompletelyIndependentList[A] -- cgit v1.2.3 From b2211a76a6e537cf2e404d424cb643f171818e92 Mon Sep 17 00:00:00 2001 From: phaller Date: Sat, 29 Sep 2012 18:15:37 +0200 Subject: SI-6442 - Add ActorDSL object for actor migration kit Removes MigrationSystem, since ActorDSL replaces it. --- .../scala/actors/migration/ActorDSL.scala | 56 ++++++++++++++++++++++ .../scala/actors/migration/MigrationSystem.scala | 37 -------------- .../scala/actors/migration/StashingActor.scala | 10 ++-- test/files/jvm/actmig-PinS_1.scala | 21 ++++---- test/files/jvm/actmig-PinS_2.scala | 23 +++++---- test/files/jvm/actmig-PinS_3.scala | 24 +++++----- test/files/jvm/actmig-instantiation.check | 4 +- test/files/jvm/actmig-instantiation.scala | 33 +++++++------ test/files/jvm/actmig-loop-react.scala | 19 ++++---- test/files/jvm/actmig-public-methods.scala | 3 +- test/files/jvm/actmig-public-methods_1.scala | 4 +- test/files/jvm/actmig-react-receive.scala | 9 ++-- test/files/jvm/actmig-react-within.scala | 5 +- test/files/jvm/actmig-receive.scala | 1 - 14 files changed, 129 insertions(+), 120 deletions(-) create mode 100644 src/actors-migration/scala/actors/migration/ActorDSL.scala delete mode 100644 src/actors-migration/scala/actors/migration/MigrationSystem.scala (limited to 'test') diff --git a/src/actors-migration/scala/actors/migration/ActorDSL.scala b/src/actors-migration/scala/actors/migration/ActorDSL.scala new file mode 100644 index 0000000000..b8cb8ec998 --- /dev/null +++ b/src/actors-migration/scala/actors/migration/ActorDSL.scala @@ -0,0 +1,56 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2005-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.actors +package migration + +import scala.actors.{ Actor, ActorRef, InternalActorRef } +import scala.collection.immutable +import scala.reflect.ClassTag + +object ActorDSL { + + private[migration] val contextStack = new ThreadLocal[immutable.Stack[Boolean]] { + override def initialValue() = immutable.Stack[Boolean]() + } + + private[this] def withCleanContext(block: => ActorRef): ActorRef = { + // push clean marker + val old = contextStack.get + contextStack.set(old.push(true)) + try { + val instance = block + + if (instance eq null) + throw new Exception("ActorRef can't be 'null'") + + instance + } finally { + val stackAfter = contextStack.get + if (stackAfter.nonEmpty) + contextStack.set(if (!stackAfter.head) stackAfter.pop.pop else stackAfter.pop) + } + } + + /** + * Create an actor from the given thunk which must produce an [[scala.actors.Actor]]. + * + * @param ctor is a by-name argument which captures an [[scala.actors.Actor]] + * factory; do not make the generated object accessible to code + * outside and do not return the same object upon subsequent invocations. + */ + def actor[T <: InternalActor: ClassTag](ctor: ⇒ T): ActorRef = { + withCleanContext { + val newActor = ctor + val newRef = new InternalActorRef(newActor) + newActor.start() + newRef + } + } + +} diff --git a/src/actors-migration/scala/actors/migration/MigrationSystem.scala b/src/actors-migration/scala/actors/migration/MigrationSystem.scala deleted file mode 100644 index 3dcb38e634..0000000000 --- a/src/actors-migration/scala/actors/migration/MigrationSystem.scala +++ /dev/null @@ -1,37 +0,0 @@ -package scala.actors.migration - -import scala.actors._ -import scala.collection._ - -object MigrationSystem { - - private[migration] val contextStack = new ThreadLocal[immutable.Stack[Boolean]] { - override def initialValue() = immutable.Stack[Boolean]() - } - - private[this] def withCleanContext(block: => ActorRef): ActorRef = { - // push clean marker - val old = contextStack.get - contextStack.set(old.push(true)) - try { - val instance = block - - if (instance eq null) - throw new Exception("Actor instance passed to actorOf can't be 'null'") - - instance - } finally { - val stackAfter = contextStack.get - if (stackAfter.nonEmpty) - contextStack.set(if (!stackAfter.head) stackAfter.pop.pop else stackAfter.pop) - } - } - - def actorOf(props: Props): ActorRef = withCleanContext { - val creator = props.creator() - val r = new InternalActorRef(creator) - creator.start() - r - } - -} \ No newline at end of file diff --git a/src/actors-migration/scala/actors/migration/StashingActor.scala b/src/actors-migration/scala/actors/migration/StashingActor.scala index d0a1432e72..c628035891 100644 --- a/src/actors-migration/scala/actors/migration/StashingActor.scala +++ b/src/actors-migration/scala/actors/migration/StashingActor.scala @@ -110,18 +110,18 @@ trait StashingActor extends InternalActor { private[actors] var behaviorStack = immutable.Stack[PartialFunction[Any, Unit]]() /* - * Checks that StashingActor can be created only by MigrationSystem.actorOf method. + * Checks that StashingActor instances can only be created using the ActorDSL. */ private[this] def creationCheck(): Unit = { // creation check (see ActorRef) - val context = MigrationSystem.contextStack.get + val context = ActorDSL.contextStack.get if (context.isEmpty) - throw new RuntimeException("In order to create StashingActor one must use actorOf.") + throw new RuntimeException("In order to create a StashingActor one must use the ActorDSL object") else { if (!context.head) - throw new RuntimeException("Only one actor can be created per actorOf call.") + throw new RuntimeException("Cannot create more than one actor") else - MigrationSystem.contextStack.set(context.push(false)) + ActorDSL.contextStack.set(context.push(false)) } } diff --git a/test/files/jvm/actmig-PinS_1.scala b/test/files/jvm/actmig-PinS_1.scala index 876688ca75..495852e812 100644 --- a/test/files/jvm/actmig-PinS_1.scala +++ b/test/files/jvm/actmig-PinS_1.scala @@ -9,7 +9,7 @@ import scala.concurrent.{ Promise, Await } object SillyActor { val startPromise = Promise[Boolean]() - val ref = MigrationSystem.actorOf(Props(() => new SillyActor, "akka.actor.default-stash-dispatcher")) + val ref = ActorDSL.actor(new SillyActor) } /* PinS, Listing 32.1: A simple actor @@ -27,7 +27,7 @@ class SillyActor extends Actor { object SeriousActor { val startPromise = Promise[Boolean]() - val ref = MigrationSystem.actorOf(Props(() => new SeriousActor, "akka.actor.default-stash-dispatcher")) + val ref = ActorDSL.actor(new SeriousActor) } class SeriousActor extends Actor { @@ -72,7 +72,7 @@ object Test extends App { /* PinS, Listing 32.2: An actor that calls receive */ - def makeEchoActor(): ActorRef = MigrationSystem.actorOf(Props(() => new Actor { + def makeEchoActor(): ActorRef = ActorDSL.actor(new Actor { def act() { while (true) { receive { @@ -83,20 +83,20 @@ object Test extends App { } } } - }, "akka.actor.default-stash-dispatcher")) + }) /* PinS, page 696 */ - def makeIntActor(): ActorRef = MigrationSystem.actorOf(Props(() => new Actor { + def makeIntActor(): ActorRef = ActorDSL.actor(new Actor { def act() { receive { case x: Int => // I only want Ints println("Got an Int: " + x) } } - }, "akka.actor.default-stash-dispatcher")) + }) - MigrationSystem.actorOf(Props(() => new Actor { + ActorDSL.actor(new Actor { def act() { trapExit = true link(SillyActor.ref) @@ -109,15 +109,14 @@ object Test extends App { case Exit(_: SeriousActor, _) => val seriousPromise2 = Promise[Boolean]() // PinS, page 694 - val seriousActor2 = MigrationSystem.actorOf(Props(() => + val seriousActor2 = ActorDSL.actor( new Actor { def act() { for (i <- 1 to 5) println("That is the question.") seriousPromise2.success(true) } - } - , "akka.actor.default-stash-dispatcher")) + }) Await.ready(seriousPromise2.future, 5 seconds) val echoActor = makeEchoActor() @@ -136,5 +135,5 @@ object Test extends App { } } } - }, "akka.actor.default-stash-dispatcher")) + }) } diff --git a/test/files/jvm/actmig-PinS_2.scala b/test/files/jvm/actmig-PinS_2.scala index 7d12578f71..508525463f 100644 --- a/test/files/jvm/actmig-PinS_2.scala +++ b/test/files/jvm/actmig-PinS_2.scala @@ -9,7 +9,7 @@ import scala.concurrent.{ Promise, Await } object SillyActor { val startPromise = Promise[Boolean]() - val ref = MigrationSystem.actorOf(Props(() => new SillyActor, "default-stash-dispatcher")) + val ref = ActorDSL.actor(new SillyActor) } /* PinS, Listing 32.1: A simple actor @@ -29,7 +29,7 @@ class SillyActor extends StashingActor { object SeriousActor { val startPromise = Promise[Boolean]() - val ref = MigrationSystem.actorOf(Props(() => new SeriousActor, "default-stash-dispatcher")) + val ref = ActorDSL.actor(new SeriousActor) } class SeriousActor extends StashingActor { @@ -44,7 +44,7 @@ class SeriousActor extends StashingActor { /* PinS, Listing 32.3: An actor that calls react */ object NameResolver { - val ref = MigrationSystem.actorOf(Props(() => new NameResolver, "default-stash-dispatcher")) + val ref = ActorDSL.actor(new NameResolver) } class NameResolver extends StashingActor { @@ -80,7 +80,7 @@ object Test extends App { /* PinS, Listing 32.2: An actor that calls receive */ - def makeEchoActor(): ActorRef = MigrationSystem.actorOf(Props(() => + def makeEchoActor(): ActorRef = ActorDSL.actor( new StashingActor { def receive = { case _ => println("Nop") } @@ -94,11 +94,11 @@ object Test extends App { } } } - }, "default-stash-dispatcher")) + }) /* PinS, page 696 */ - def makeIntActor(): ActorRef = MigrationSystem.actorOf(Props(() =>new StashingActor { + def makeIntActor(): ActorRef = ActorDSL.actor(new StashingActor { def receive = { case _ => println("Nop") } @@ -108,9 +108,9 @@ object Test extends App { println("Got an Int: " + x) } } - }, "default-stash-dispatcher")) + }) - MigrationSystem.actorOf(Props(() => new StashingActor { + ActorDSL.actor(new StashingActor { def receive = { case _ => println("Nop") } @@ -126,7 +126,7 @@ object Test extends App { case Exit(_: SeriousActor, _) => val seriousPromise2 = Promise[Boolean]() // PinS, page 694 - val seriousActor2 = MigrationSystem.actorOf(Props(() =>{ + val seriousActor2 = ActorDSL.actor( new StashingActor { def receive = { case _ => println("Nop") } @@ -136,8 +136,7 @@ object Test extends App { println("That is the question.") seriousPromise2.success(true) } - } - }, "default-stash-dispatcher")) + }) Await.ready(seriousPromise2.future, 5 seconds) val echoActor = makeEchoActor() @@ -156,5 +155,5 @@ object Test extends App { } } } - }, "default-stash-dispatcher")) + }) } diff --git a/test/files/jvm/actmig-PinS_3.scala b/test/files/jvm/actmig-PinS_3.scala index c2943008b0..6c6ec6789b 100644 --- a/test/files/jvm/actmig-PinS_3.scala +++ b/test/files/jvm/actmig-PinS_3.scala @@ -7,10 +7,9 @@ import scala.actors.migration._ import scala.concurrent.duration._ import scala.concurrent.{ Promise, Await } - object SillyActor { val startPromise = Promise[Boolean]() - val ref = MigrationSystem.actorOf(Props(() => new SillyActor, "default-stash-dispatcher")) + val ref = ActorDSL.actor(new SillyActor) } /* PinS, Listing 32.1: A simple actor @@ -32,7 +31,7 @@ class SillyActor extends StashingActor { object SeriousActor { val startPromise = Promise[Boolean]() - val ref = MigrationSystem.actorOf(Props(() => new SeriousActor, "default-stash-dispatcher")) + val ref = ActorDSL.actor(new SeriousActor) } class SeriousActor extends StashingActor { @@ -48,7 +47,7 @@ class SeriousActor extends StashingActor { /* PinS, Listing 32.3: An actor that calls react */ object NameResolver { - val ref = MigrationSystem.actorOf(Props(() => new NameResolver, "default-stash-dispatcher")) + val ref = ActorDSL.actor(new NameResolver) } class NameResolver extends StashingActor { @@ -78,7 +77,7 @@ object Test extends App { /* PinS, Listing 32.2: An actor that calls receive */ - def makeEchoActor(): ActorRef = MigrationSystem.actorOf(Props(() => new StashingActor { + def makeEchoActor(): ActorRef = ActorDSL.actor(new StashingActor { def receive = { // how to handle receive case 'stop => @@ -86,11 +85,11 @@ object Test extends App { case msg => println("received message: " + msg) } - }, "default-stash-dispatcher")) + }) /* PinS, page 696 */ - def makeIntActor(): ActorRef = MigrationSystem.actorOf(Props(() => new StashingActor { + def makeIntActor(): ActorRef = ActorDSL.actor(new StashingActor { def receive = { case x: Int => // I only want Ints @@ -99,9 +98,9 @@ object Test extends App { context.stop(self) case _ => stash() } - }, "default-stash-dispatcher")) + }) - MigrationSystem.actorOf(Props(() => new StashingActor { + ActorDSL.actor(new StashingActor { val silly = SillyActor.ref override def preStart() { @@ -119,7 +118,7 @@ object Test extends App { case Terminated(`serious`) => val seriousPromise2 = Promise[Boolean]() // PinS, page 694 - val seriousActor2 = MigrationSystem.actorOf(Props(() => { + val seriousActor2 = ActorDSL.actor( new StashingActor { def receive = { case _ => context.stop(self) } @@ -130,8 +129,7 @@ object Test extends App { seriousPromise2.success(true) context.stop(self) } - } - }, "default-stash-dispatcher")) + }) Await.ready(seriousPromise2.future, 5 seconds) val echoActor = makeEchoActor() @@ -162,5 +160,5 @@ object Test extends App { println("Stash 3 " + m) stash(m) } - }, "default-stash-dispatcher")) + }) } diff --git a/test/files/jvm/actmig-instantiation.check b/test/files/jvm/actmig-instantiation.check index 4c13d5c0a1..08ef979794 100644 --- a/test/files/jvm/actmig-instantiation.check +++ b/test/files/jvm/actmig-instantiation.check @@ -1,5 +1,5 @@ -OK error: java.lang.RuntimeException: In order to create StashingActor one must use actorOf. -OK error: java.lang.RuntimeException: Only one actor can be created per actorOf call. +OK error: java.lang.RuntimeException: In order to create a StashingActor one must use the ActorDSL object +OK error: java.lang.RuntimeException: Cannot create more than one actor 0 100 200 diff --git a/test/files/jvm/actmig-instantiation.scala b/test/files/jvm/actmig-instantiation.scala index d54dff9558..2e3ffc3c30 100644 --- a/test/files/jvm/actmig-instantiation.scala +++ b/test/files/jvm/actmig-instantiation.scala @@ -2,7 +2,6 @@ * NOTE: Code snippets from this test are included in the Actor Migration Guide. In case you change * code in these tests prior to the 2.10.0 release please send the notification to @vjovanov. */ -import scala.actors.migration.MigrationSystem._ import scala.actors.migration._ import scala.actors.Actor._ import scala.actors._ @@ -35,53 +34,53 @@ object Test { a1 ! 100 // simple instantiation - val a2 = MigrationSystem.actorOf(Props(() => new TestStashingActor, "akka.actor.default-stash-dispatcher")) + val a2 = ActorDSL.actor(new TestStashingActor) a2 ! 200 toStop += a2 // actor of with scala actor - val a3 = MigrationSystem.actorOf(Props(() => actor { + val a3 = ActorDSL.actor(actor { react { case v: Int => Test.append(v); Test.latch.countDown() } - }, "akka.actor.default-stash-dispatcher")) + }) a3 ! 300 // using the manifest - val a4 = MigrationSystem.actorOf(Props(() => new TestStashingActor, "akka.actor.default-stash-dispatcher")) + val a4 = ActorDSL.actor(new TestStashingActor) a4 ! 400 toStop += a4 // deterministic part of a test - // creation without actorOf + // creation without actor try { val a3 = new TestStashingActor a3 ! -1 } catch { - case e => println("OK error: " + e) + case e: Throwable => println("OK error: " + e) } - // actorOf double creation + // actor double creation try { - val a3 = MigrationSystem.actorOf(Props(() => { + val a3 = ActorDSL.actor({ new TestStashingActor new TestStashingActor - }, "akka.actor.default-stash-dispatcher")) + }) a3 ! -1 } catch { - case e => println("OK error: " + e) + case e: Throwable => println("OK error: " + e) } - // actorOf nesting + // actor nesting try { - val a5 = MigrationSystem.actorOf(Props(() => { - val a6 = MigrationSystem.actorOf(Props(() => new TestStashingActor, "akka.actor.default-stash-dispatcher")) + val a5 = ActorDSL.actor({ + val a6 = ActorDSL.actor(new TestStashingActor) toStop += a6 new TestStashingActor - }, "akka.actor.default-stash-dispatcher")) + }) a5 ! 500 toStop += a5 } catch { - case e => println("Should not throw an exception: " + e) + case e: Throwable => println("Should not throw an exception: " + e) } // output @@ -93,4 +92,4 @@ object Test { buff.sorted.foreach(println) toStop.foreach(_ ! PoisonPill) } -} \ No newline at end of file +} diff --git a/test/files/jvm/actmig-loop-react.scala b/test/files/jvm/actmig-loop-react.scala index 7f4c6f96dc..c9a3664526 100644 --- a/test/files/jvm/actmig-loop-react.scala +++ b/test/files/jvm/actmig-loop-react.scala @@ -2,7 +2,6 @@ * NOTE: Code snippets from this test are included in the Actor Migration Guide. In case you change * code in these tests prior to the 2.10.0 release please send the notification to @vjovanov. */ -import scala.actors.migration.MigrationSystem._ import scala.actors.Actor._ import scala.actors._ import scala.actors.migration._ @@ -40,7 +39,7 @@ object Test { Await.ready(finishedLWCR1.future, 5 seconds) // Loop with Condition Snippet - migrated - val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { + val myAkkaActor = ActorDSL.actor(new StashingActor { def receive = { case x: Int => @@ -51,7 +50,7 @@ object Test { context.stop(self) } } - }, "default-stashing-dispatcher")) + }) myAkkaActor ! 1 myAkkaActor ! 42 } @@ -88,7 +87,7 @@ object Test { Await.ready(finishedTNR1.future, 5 seconds) // Loop with Condition Snippet - migrated - val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { + val myAkkaActor = ActorDSL.actor(new StashingActor { def receive = { case x: Int => @@ -107,7 +106,7 @@ object Test { context.unbecome() }).orElse { case x => stash() }) } - }, "default-stashing-dispatcher")) + }) myAkkaActor ! 1 myAkkaActor ! "I am a String" @@ -117,7 +116,7 @@ object Test { def exceptionHandling() = { // Stashing actor with act and exception handler - val myActor = MigrationSystem.actorOf(Props(() => new StashingActor { + val myActor = ActorDSL.actor(new StashingActor { def receive = { case _ => println("Dummy method.") } override def act() = { @@ -138,7 +137,7 @@ object Test { case x: Exception => println("scala got exception") } - }, "default-stashing-dispatcher")) + }) myActor ! "work" myActor ! "fail" @@ -146,7 +145,7 @@ object Test { Await.ready(finishedEH1.future, 5 seconds) // Stashing actor in Akka style - val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { + val myAkkaActor = ActorDSL.actor(new StashingActor { def receive = PFCatch({ case "fail" => throw new Exception("failed") @@ -156,14 +155,14 @@ object Test { finishedEH.success(true) context.stop(self) }, { case x: Exception => println("akka got exception") }) - }, "default-stashing-dispatcher")) + }) myAkkaActor ! "work" myAkkaActor ! "fail" myAkkaActor ! "die" } - def main(args: Array[String]) = { + def main(args: Array[String]): Unit = { testLoopWithConditionReact() Await.ready(finishedLWCR.future, 5 seconds) exceptionHandling() diff --git a/test/files/jvm/actmig-public-methods.scala b/test/files/jvm/actmig-public-methods.scala index 58d7a1a9d4..8891c80668 100644 --- a/test/files/jvm/actmig-public-methods.scala +++ b/test/files/jvm/actmig-public-methods.scala @@ -5,7 +5,6 @@ import scala.collection.mutable.ArrayBuffer import scala.actors.Actor._ import scala.actors._ -import scala.actors.migration.MigrationSystem import scala.util.continuations._ import java.util.concurrent.{ TimeUnit, CountDownLatch } @@ -71,4 +70,4 @@ object Test { buff.sorted.foreach(println) toStop.foreach(_ ! 'stop) } -} \ No newline at end of file +} diff --git a/test/files/jvm/actmig-public-methods_1.scala b/test/files/jvm/actmig-public-methods_1.scala index 15516a5d51..db21ab983c 100644 --- a/test/files/jvm/actmig-public-methods_1.scala +++ b/test/files/jvm/actmig-public-methods_1.scala @@ -28,7 +28,7 @@ object Test { def main(args: Array[String]) = { - val respActor = MigrationSystem.actorOf(Props(() => actor { + val respActor = ActorDSL.actor(actor { loop { react { case (x: String, time: Long) => @@ -41,7 +41,7 @@ object Test { exit() } } - }, "akka.actor.default-stash-dispatcher")) + }) toStop += respActor diff --git a/test/files/jvm/actmig-react-receive.scala b/test/files/jvm/actmig-react-receive.scala index 6adeac8b52..bf70ce0c46 100644 --- a/test/files/jvm/actmig-react-receive.scala +++ b/test/files/jvm/actmig-react-receive.scala @@ -2,7 +2,6 @@ * NOTE: Code snippets from this test are included in the Actor Migration Guide. In case you change * code in these tests prior to the 2.10.0 release please send the notification to @vjovanov. */ -import scala.actors.migration.MigrationSystem._ import scala.actors.Actor._ import scala.actors._ import scala.actors.migration._ @@ -39,7 +38,7 @@ object Test { Await.ready(finishedRSC1.future, 5 seconds) // React Snippet - migrated - val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { + val myAkkaActor = ActorDSL.actor(new StashingActor { override def preStart() = { println("do before") } @@ -63,7 +62,7 @@ object Test { finishedRSC.success(true) } - }, "default-stashing-dispatcher")) + }) myAkkaActor ! 1 myAkkaActor ! "1" Await.ready(finishedRSC.future, 5 seconds) @@ -88,7 +87,7 @@ object Test { Await.ready(finishedRS1.future, 5 seconds) // React Snippet - migrated - val myAkkaActor = MigrationSystem.actorOf(Props(() => new StashingActor { + val myAkkaActor = ActorDSL.actor(new StashingActor { override def preStart() = { println("do before") } @@ -105,7 +104,7 @@ object Test { finishedRS.success(true) } - }, "default-stashing-dispatcher")) + }) myAkkaActor ! 1 Await.ready(finishedRS.future, 5 seconds) diff --git a/test/files/jvm/actmig-react-within.scala b/test/files/jvm/actmig-react-within.scala index 43350ef120..3057398cb5 100644 --- a/test/files/jvm/actmig-react-within.scala +++ b/test/files/jvm/actmig-react-within.scala @@ -2,7 +2,6 @@ * NOTE: Code snippets from this test are included in the Actor Migration Guide. In case you change * code in these tests prior to the 2.10.0 release please send the notification to @vjovanov. */ -import scala.actors.migration.MigrationSystem._ import scala.actors.Actor._ import scala.actors._ import scala.actors.migration._ @@ -27,7 +26,7 @@ object Test { } } - val myActor = MigrationSystem.actorOf(Props(() => new StashingActor { + val myActor = ActorDSL.actor(new StashingActor { context.setReceiveTimeout(1 millisecond) def receive = { case ReceiveTimeout => @@ -37,7 +36,7 @@ object Test { case _ => println("Should not occur.") } - }, "default-stashing-dispatcher")) + }) } def main(args: Array[String]) = { diff --git a/test/files/jvm/actmig-receive.scala b/test/files/jvm/actmig-receive.scala index 03dc1be63b..308643cf41 100644 --- a/test/files/jvm/actmig-receive.scala +++ b/test/files/jvm/actmig-receive.scala @@ -2,7 +2,6 @@ * NOTE: Code snippets from this test are included in the Actor Migration Guide. In case you change * code in these tests prior to the 2.10.0 release please send the notification to @vjovanov. */ -import scala.actors.migration.MigrationSystem._ import scala.actors.Actor._ import scala.actors._ import scala.actors.migration._ -- cgit v1.2.3 From 18fd93b5ec7e439b59b75f96e976aad6025a76f4 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 29 Sep 2012 13:34:25 -0700 Subject: Revert "SI-4881 infer variance from formals, then result" This reverts commit 5c5e8d4dcd151a6e2bf9e7c259c618b9b4eff00f. --- .../scala/tools/nsc/typechecker/Infer.scala | 15 ++--------- test/files/neg/t5845.check | 5 +++- test/files/pos/t4881.scala | 31 ---------------------- 3 files changed, 6 insertions(+), 45 deletions(-) delete mode 100644 test/files/pos/t4881.scala (limited to 'test') diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 0c3dcb9342..cb5fc8df5a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -517,7 +517,7 @@ trait Infer extends Checkable { val tvars = tparams map freshVar if (isConservativelyCompatible(restpe.instantiateTypeParams(tparams, tvars), pt)) map2(tparams, tvars)((tparam, tvar) => - instantiateToBound(tvar, inferVariance(formals, restpe)(tparam))) + instantiateToBound(tvar, varianceInTypes(formals)(tparam))) else tvars map (tvar => WildcardType) } @@ -647,24 +647,13 @@ trait Infer extends Checkable { "argument expression's type is not compatible with formal parameter type" + foundReqMsg(tp1, pt1)) } } - val targs = solvedTypes( - tvars, tparams, tparams map inferVariance(formals, restpe), + tvars, tparams, tparams map varianceInTypes(formals), false, lubDepth(formals) max lubDepth(argtpes) ) adjustTypeArgs(tparams, tvars, targs, restpe) } - /** Determine which variance to assume for the type paraneter. We first chose the variance - * that minimizes any formal parameters. If that is still undetermined, because the type parameter - * does not appear as a formal parameter type, then we pick the variance so that it minimizes the - * method's result type instead. - */ - private def inferVariance(formals: List[Type], restpe: Type)(tparam: Symbol): Int = { - val v = varianceInTypes(formals)(tparam) - if (v != VarianceFlags) v else varianceInType(restpe)(tparam) - } - private[typechecker] def followApply(tp: Type): Type = tp match { case NullaryMethodType(restp) => val restp1 = followApply(restp) diff --git a/test/files/neg/t5845.check b/test/files/neg/t5845.check index c0b402fccb..8c6100d6de 100644 --- a/test/files/neg/t5845.check +++ b/test/files/neg/t5845.check @@ -1,4 +1,7 @@ +t5845.scala:9: error: value +++ is not a member of Int + println(5 +++ 5) + ^ t5845.scala:15: error: value +++ is not a member of Int println(5 +++ 5) ^ -one error found +two errors found diff --git a/test/files/pos/t4881.scala b/test/files/pos/t4881.scala deleted file mode 100644 index 46cfad9793..0000000000 --- a/test/files/pos/t4881.scala +++ /dev/null @@ -1,31 +0,0 @@ -class Contra[-T] -trait A -trait B extends A -trait C extends B - -// test improved variance inference: first try formals to see in which variance positions the type param appears; -// only when that fails to determine variance, look at result type -object Test { - def contraLBUB[a >: C <: A](): Contra[a] = null - def contraLB[a >: C](): Contra[a] = null - -{ - val x = contraLBUB() //inferred Contra[C] instead of Contra[A] - val x1: Contra[A] = x -} - -{ - val x = contraLB() //inferred Contra[C] instead of Contra[Any] - val x1: Contra[Any] = x -} - -{ - val x = contraLBUB // make sure it does the same thing as its ()-less counterpart - val x1: Contra[A] = x -} - -{ - val x = contraLB - val x1: Contra[Any] = x -} -} -- cgit v1.2.3 From 6ea54efa60b54016daa339b1e13c5241a7d5feec Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 29 Sep 2012 13:34:48 -0700 Subject: Test case for SI-6311. This covers the situation which broke in 5c5e8d4dcd, reverted in the previous commit. --- test/files/pos/t6311.scala | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test/files/pos/t6311.scala (limited to 'test') diff --git a/test/files/pos/t6311.scala b/test/files/pos/t6311.scala new file mode 100644 index 0000000000..d27ad2f502 --- /dev/null +++ b/test/files/pos/t6311.scala @@ -0,0 +1,5 @@ +class A { + def fooMinimal[T, Coll <: Traversable[T]](msg: String)(param1: Traversable[T])(param2: Coll): Traversable[T] = throw new Exception() + + fooMinimal("")(List(1))(List(2)) +} -- cgit v1.2.3