diff options
author | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-02 04:19:47 -0700 |
---|---|---|
committer | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-02 04:19:47 -0700 |
commit | 6e1ff1c92d32b567a41b10c0e4321adf01d3e616 (patch) | |
tree | c23ef6bdf01f643ce98204c0e3d10420d1a86058 | |
parent | 6b87cdcd7bd6d1932e87e6bf8dc6029d6461a488 (diff) | |
parent | 35316be5a89b2c9622e92594245aaf72a3820c88 (diff) | |
download | scala-6e1ff1c92d32b567a41b10c0e4321adf01d3e616.tar.gz scala-6e1ff1c92d32b567a41b10c0e4321adf01d3e616.tar.bz2 scala-6e1ff1c92d32b567a41b10c0e4321adf01d3e616.zip |
Merge pull request #1232 from paulp/topic/210-errors-and-warnings
Topic/210 errors and warnings
22 files changed, 359 insertions, 158 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 773d9a6f50..b7195b0349 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -85,10 +85,33 @@ trait ContextErrors { def typeErrorMsg(found: Type, req: Type, possiblyMissingArgs: Boolean) = { def missingArgsMsg = if (possiblyMissingArgs) "\n possible cause: missing arguments for method or constructor" else "" + "type mismatch" + foundReqMsg(found, req) + missingArgsMsg } } + def notAnyRefMessage(found: Type): String = { + val tp = found.widen + def name = tp.typeSymbol.nameString + def parents = tp.parents filterNot isTrivialTopType + def onlyAny = tp.parents forall (_.typeSymbol == AnyClass) + def parents_s = ( if (parents.isEmpty) tp.parents else parents ) mkString ", " + def what = ( + if (tp.typeSymbol.isAbstractType) { + val descr = if (onlyAny) "unbounded" else "bounded only by " + parents_s + s"$name is $descr, which means AnyRef is not a known parent" + } + else if (tp.typeSymbol.isAnonOrRefinementClass) + s"the parents of this type ($parents_s) extend Any, not AnyRef" + else + s"$name extends Any, not AnyRef" + ) + if (isPrimitiveValueType(found)) "" else "\n" + + s"""|Note that $what. + |Such types can participate in value classes, but instances + |cannot appear in singleton types or in reference comparisons.""".stripMargin + } + import ErrorUtils._ trait TyperContextErrors { @@ -296,12 +319,17 @@ trait ContextErrors { else "" ) - companion + semicolon + val notAnyRef = ( + if (ObjectClass.info.member(name).exists) notAnyRefMessage(target) + else "" + ) + companion + notAnyRef + semicolon } + def targetStr = targetKindString + target.directObjectString withAddendum(qual.pos)( - if (name == nme.CONSTRUCTOR) target + " does not have a constructor" - else nameString + " is not a member of " + targetKindString + target.directObjectString + addendum - ) + if (name == nme.CONSTRUCTOR) s"$target does not have a constructor" + else s"$nameString is not a member of $targetStr$addendum" + ) } issueNormalTypeError(sel, errMsg) // the error has to be set for the copied tree, otherwise @@ -1095,44 +1123,42 @@ trait ContextErrors { pre1: String, pre2: String, trailer: String) (isView: Boolean, pt: Type, tree: Tree)(implicit context0: Context) = { if (!info1.tpe.isErroneous && !info2.tpe.isErroneous) { - val coreMsg = - pre1+" "+info1.sym.fullLocationString+" of type "+info1.tpe+"\n "+ - pre2+" "+info2.sym.fullLocationString+" of type "+info2.tpe+"\n "+ - trailer - val errMsg = - if (isView) { - val found = pt.typeArgs(0) - val req = pt.typeArgs(1) - def defaultExplanation = - "Note that implicit conversions are not applicable because they are ambiguous:\n "+ - coreMsg+"are possible conversion functions from "+ found+" to "+req - - def explanation = { - val sym = found.typeSymbol - // Explain some common situations a bit more clearly. - if (AnyRefClass.tpe <:< req) { - if (sym == AnyClass || sym == UnitClass) { - "Note: " + sym.name + " is not implicitly converted to AnyRef. You can safely\n" + - "pattern match `x: AnyRef` or cast `x.asInstanceOf[AnyRef]` to do so." - } - else boxedClass get sym match { - case Some(boxed) => - "Note: an implicit exists from " + sym.fullName + " => " + boxed.fullName + ", but\n" + - "methods inherited from Object are rendered ambiguous. This is to avoid\n" + - "a blanket implicit which would convert any " + sym.fullName + " to any AnyRef.\n" + - "You may wish to use a type ascription: `x: " + boxed.fullName + "`." - case _ => - defaultExplanation - } - } - else defaultExplanation - } - - typeErrorMsg(found, req, infer.isPossiblyMissingArgs(found, req)) + "\n" + explanation - } else { - "ambiguous implicit values:\n "+coreMsg + "match expected type "+pt + def coreMsg = + s"""| $pre1 ${info1.sym.fullLocationString} of type ${info1.tpe} + | $pre2 ${info2.sym.fullLocationString} of type ${info2.tpe} + | $trailer""".stripMargin + def viewMsg = { + val found :: req :: _ = pt.typeArgs + def explanation = { + val sym = found.typeSymbol + // Explain some common situations a bit more clearly. Some other + // failures which have nothing to do with implicit conversions + // per se, but which manifest as implicit conversion conflicts + // involving Any, are further explained from foundReqMsg. + if (AnyRefClass.tpe <:< req) ( + if (sym == AnyClass || sym == UnitClass) ( + s"""|Note: ${sym.name} is not implicitly converted to AnyRef. You can safely + |pattern match `x: AnyRef` or cast `x.asInstanceOf[AnyRef]` to do so.""".stripMargin + ) + else boxedClass get sym map (boxed => + s"""|Note: an implicit exists from ${sym.fullName} => ${boxed.fullName}, but + |methods inherited from Object are rendered ambiguous. This is to avoid + |a blanket implicit which would convert any ${sym.fullName} to any AnyRef. + |You may wish to use a type ascription: `x: ${boxed.fullName}`.""".stripMargin + ) getOrElse "" + ) + else + s"""|Note that implicit conversions are not applicable because they are ambiguous: + |${coreMsg}are possible conversion functions from $found to $req""".stripMargin } - context.issueAmbiguousError(AmbiguousTypeError(tree, tree.pos, errMsg)) + typeErrorMsg(found, req, infer.isPossiblyMissingArgs(found, req)) + ( + if (explanation == "") "" else "\n" + explanation + ) + } + context.issueAmbiguousError(AmbiguousTypeError(tree, tree.pos, + if (isView) viewMsg + else s"ambiguous implicit values:\n${coreMsg}match expected type $pt") + ) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 28636fc76e..1b3602fca2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -280,7 +280,16 @@ trait Infer { def issue(err: AbsTypeError): Unit = context.issue(err) - def isPossiblyMissingArgs(found: Type, req: Type) = (found.resultApprox ne found) && isWeaklyCompatible(found.resultApprox, req) + def isPossiblyMissingArgs(found: Type, req: Type) = ( + false + /** However it is that this condition is expected to imply + * "is possibly missing args", it is too weak. It is + * better to say nothing than to offer misleading guesses. + + (found.resultApprox ne found) + && isWeaklyCompatible(found.resultApprox, req) + */ + ) def explainTypes(tp1: Type, tp2: Type) = withDisambiguation(List(), tp1, tp2)(global.explainTypes(tp1, tp2)) diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index f0dca64a00..f8a5c401df 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -252,6 +252,13 @@ trait TypeDiagnostics { } "" // no elaborable variance situation found } + + // For found/required errors where AnyRef would have sufficed: + // explain in greater detail. + def explainAnyVsAnyRef(found: Type, req: Type): String = { + if (AnyRefClass.tpe <:< req) notAnyRefMessage(found) else "" + } + // TODO - figure out how to avoid doing any work at all // when the message will never be seen. I though context.reportErrors // being false would do that, but if I return "<suppressed>" under @@ -261,7 +268,10 @@ trait TypeDiagnostics { ";\n found : " + found.toLongString + existentialContext(found) + explainAlias(found) + "\n required: " + req + existentialContext(req) + explainAlias(req) ) - withDisambiguation(Nil, found, req)(baseMessage) + explainVariance(found, req) + ( withDisambiguation(Nil, found, req)(baseMessage) + + explainVariance(found, req) + + explainAnyVsAnyRef(found, req) + ) } case class TypeDiag(tp: Type, sym: Symbol) extends Ordered[TypeDiag] { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index f6baf02c3e..b6dab13111 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -233,10 +233,11 @@ trait Typers extends Modes with Adaptations with Tags { * @param tree ... * @return ... */ - def checkStable(tree: Tree): Tree = + def checkStable(tree: Tree): Tree = ( if (treeInfo.isExprSafeToInline(tree)) tree else if (tree.isErrorTyped) tree else UnstableTreeError(tree) + ) /** Would tree be a stable (i.e. a pure expression) if the type * of its symbol was not volatile? @@ -5201,7 +5202,10 @@ trait Typers extends Modes with Adaptations with Tags { def typedSingletonTypeTree(tree: SingletonTypeTree) = { val ref1 = checkStable( - typed(tree.ref, EXPRmode | QUALmode | (mode & TYPEPATmode), AnyRefClass.tpe)) + context.withImplicitsDisabled( + typed(tree.ref, EXPRmode | QUALmode | (mode & TYPEPATmode), AnyRefClass.tpe) + ) + ) tree setType ref1.tpe.resultType } diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 98d42b724c..c21ebfe997 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -218,6 +218,32 @@ trait Definitions extends api.StandardDefinitions { case _ => null } + /** Fully initialize the symbol, type, or scope. + */ + def fullyInitializeSymbol(sym: Symbol): Symbol = { + sym.initialize + fullyInitializeType(sym.info) + fullyInitializeType(sym.tpe) + sym + } + def fullyInitializeType(tp: Type): Type = { + tp.typeParams foreach fullyInitializeSymbol + tp.paramss.flatten foreach fullyInitializeSymbol + tp + } + def fullyInitializeScope(scope: Scope): Scope = { + scope.sorted foreach fullyInitializeSymbol + scope + } + /** Is this type equivalent to Any, AnyVal, or AnyRef? */ + def isTrivialTopType(tp: Type) = ( + tp =:= AnyClass.tpe + || tp =:= AnyValClass.tpe + || tp =:= AnyRefClass.tpe + ) + /** Does this type have a parent which is none of Any, AnyVal, or AnyRef? */ + def hasNonTrivialParent(tp: Type) = tp.parents exists (t => !isTrivialTopType(tp)) + private def fixupAsAnyTrait(tpe: Type): Type = tpe match { case ClassInfoType(parents, decls, clazz) => if (parents.head.typeSymbol == AnyClass) tpe @@ -383,7 +409,7 @@ trait Definitions extends api.StandardDefinitions { def isRepeated(param: Symbol) = isRepeatedParamType(param.tpe) def isCastSymbol(sym: Symbol) = sym == Any_asInstanceOf || sym == Object_asInstanceOf - def isJavaVarArgsMethod(m: Symbol) = m.isMethod && isJavaVarArgs(m.info.params) + def isJavaVarArgsMethod(m: Symbol) = m.isMethod && isJavaVarArgs(m.info.params) def isJavaVarArgs(params: Seq[Symbol]) = params.nonEmpty && isJavaRepeatedParamType(params.last.tpe) def isScalaVarArgs(params: Seq[Symbol]) = params.nonEmpty && isScalaRepeatedParamType(params.last.tpe) def isVarArgsList(params: Seq[Symbol]) = params.nonEmpty && isRepeatedParamType(params.last.tpe) diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index b13b893635..c266e26895 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -1010,7 +1010,11 @@ trait Types extends api.Types { self: SymbolTable => def toLongString = { val str = toString if (str == "type") widen.toString - else if ((str endsWith ".type") && !typeSymbol.isModuleClass) str + " (with underlying type " + widen + ")" + else if ((str endsWith ".type") && !typeSymbol.isModuleClass) + widen match { + case RefinedType(_, _) => "" + widen + case _ => s"$str (with underlying type $widen)" + } else str } @@ -1632,7 +1636,7 @@ trait Types extends api.Types { self: SymbolTable => override def safeToString: String = parentsString(parents) + ( (if (settings.debug.value || parents.isEmpty || (decls.elems ne null)) - decls.mkString("{", "; ", "}") else "") + fullyInitializeScope(decls).mkString("{", "; ", "}") else "") ) } @@ -1819,7 +1823,6 @@ trait Types extends api.Types { self: SymbolTable => false })) } - override def kind = "RefinedType" } @@ -2005,9 +2008,11 @@ trait Types extends api.Types { self: SymbolTable => /** A nicely formatted string with newlines and such. */ def formattedToString: String = - parents.mkString("\n with ") + - (if (settings.debug.value || parents.isEmpty || (decls.elems ne null)) - decls.mkString(" {\n ", "\n ", "\n}") else "") + parents.mkString("\n with ") + ( + if (settings.debug.value || parents.isEmpty || (decls.elems ne null)) + fullyInitializeScope(decls).mkString(" {\n ", "\n ", "\n}") + else "" + ) } object ClassInfoType extends ClassInfoTypeExtractor @@ -2466,7 +2471,7 @@ trait Types extends api.Types { self: SymbolTable => def refinementString = ( if (sym.isStructuralRefinement) ( - decls filter (sym => sym.isPossibleInRefinement && sym.isPublic) + fullyInitializeScope(decls) filter (sym => sym.isPossibleInRefinement && sym.isPublic) map (_.defString) mkString("{", "; ", "}") ) diff --git a/test/files/buildmanager/t2650_3/t2650_3.check b/test/files/buildmanager/t2650_3/t2650_3.check index c109800d9c..5c6326d59f 100644 --- a/test/files/buildmanager/t2650_3/t2650_3.check +++ b/test/files/buildmanager/t2650_3/t2650_3.check @@ -10,6 +10,5 @@ B.scala:2: error: type mismatch; found : a.T (which expands to) Long required: Int - possible cause: missing arguments for method or constructor def x(a: A): Int = a.x ^ diff --git a/test/files/buildmanager/t2650_4/t2650_4.check b/test/files/buildmanager/t2650_4/t2650_4.check index 89536776bd..a4aeaddfbb 100644 --- a/test/files/buildmanager/t2650_4/t2650_4.check +++ b/test/files/buildmanager/t2650_4/t2650_4.check @@ -10,6 +10,5 @@ B.scala:2: error: type mismatch; found : a.T2 (which expands to) Long required: Int - possible cause: missing arguments for method or constructor def x(a: A): Int = a.x ^ diff --git a/test/files/neg/any-vs-anyref.check b/test/files/neg/any-vs-anyref.check new file mode 100644 index 0000000000..63c4853130 --- /dev/null +++ b/test/files/neg/any-vs-anyref.check @@ -0,0 +1,64 @@ +any-vs-anyref.scala:6: error: type mismatch; + found : a.type (with underlying type A) + required: AnyRef +Note that A is bounded only by Equals, which means AnyRef is not a known parent. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo1[A <: Product](a: A) = { type X = a.type } + ^ +any-vs-anyref.scala:7: error: type mismatch; + found : a.type (with underlying type A) + required: AnyRef +Note that A is bounded only by Product, Quux, which means AnyRef is not a known parent. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo2[A <: Product with Quux](a: A) = { type X = a.type } + ^ +any-vs-anyref.scala:8: error: type mismatch; + found : a.type (with underlying type Product) + required: AnyRef +Note that Product extends Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo3(a: Product) = { type X = a.type } + ^ +any-vs-anyref.scala:9: error: type mismatch; + found : Product with Quux + required: AnyRef +Note that the parents of this type (Product, Quux) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo4(a: Product with Quux) = { type X = a.type } + ^ +any-vs-anyref.scala:10: error: value eq is not a member of Quux with Product +Note that the parents of this type (Quux, Product) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo5(x: Quux with Product) = (x eq "abc") && ("abc" eq x) + ^ +any-vs-anyref.scala:11: error: value eq is not a member of Quux with Product{def f: Int} +Note that the parents of this type (Quux, Product) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo6(x: Quux with Product { def f: Int }) = (x eq "abc") && ("abc" eq x) + ^ +any-vs-anyref.scala:12: error: type mismatch; + found : Quux with Product{def eq(other: String): Boolean} + required: AnyRef +Note that the parents of this type (Quux, Product) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo7(x: Quux with Product { def eq(other: String): Boolean }) = (x eq "abc") && ("abc" eq x) + ^ +any-vs-anyref.scala:22: error: value eq is not a member of Bippy +Note that Bippy extends Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def bad1(x: Bippy, y: Bippy) = x eq y + ^ +any-vs-anyref.scala:27: error: type mismatch; + found : Quux{def g(x: String): String} + required: Quux{def g(x: Int): Int} + f(new Quux { def g(x: String) = x }) + ^ +9 errors found diff --git a/test/files/neg/any-vs-anyref.scala b/test/files/neg/any-vs-anyref.scala new file mode 100644 index 0000000000..8d237fbaec --- /dev/null +++ b/test/files/neg/any-vs-anyref.scala @@ -0,0 +1,29 @@ +trait Quux extends Any +trait QuuxRef extends AnyRef +final class Bippy(val x: Any) extends AnyVal with Quux + +object Foo { + def foo1[A <: Product](a: A) = { type X = a.type } + def foo2[A <: Product with Quux](a: A) = { type X = a.type } + def foo3(a: Product) = { type X = a.type } + def foo4(a: Product with Quux) = { type X = a.type } + def foo5(x: Quux with Product) = (x eq "abc") && ("abc" eq x) + def foo6(x: Quux with Product { def f: Int }) = (x eq "abc") && ("abc" eq x) + def foo7(x: Quux with Product { def eq(other: String): Boolean }) = (x eq "abc") && ("abc" eq x) + + def ok1[A <: QuuxRef](a: A) = { type X = a.type } + def ok2[A <: Product with QuuxRef](a: A) = { type X = a.type } + def ok3(a: QuuxRef) = { type X = a.type } + def ok4(a: Product with QuuxRef) = { type X = a.type } + def ok5(x: QuuxRef with Product) = (x eq "abc") && ("abc" eq x) + def ok6(x: QuuxRef with Product { def f: Int }) = (x eq "abc") && ("abc" eq x) + def ok7(x: QuuxRef { def eq(other: String): Boolean }) = (x eq "abc") && ("abc" eq x) + + def bad1(x: Bippy, y: Bippy) = x eq y +} + +object Bar { + def f(x: Quux { def g(x: Int): Int }): Int = x g 5 + f(new Quux { def g(x: String) = x }) + f(new Quux { def g(x: Int) = x }) +} diff --git a/test/files/neg/not-possible-cause.check b/test/files/neg/not-possible-cause.check new file mode 100644 index 0000000000..5c09fa1545 --- /dev/null +++ b/test/files/neg/not-possible-cause.check @@ -0,0 +1,9 @@ +not-possible-cause.scala:2: error: type mismatch; + found : a.type (with underlying type A) + required: AnyRef +Note that A is bounded only by Equals, which means AnyRef is not a known parent. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo[A <: Product](a: A) { type X = a.type } + ^ +one error found diff --git a/test/files/neg/not-possible-cause.scala b/test/files/neg/not-possible-cause.scala new file mode 100644 index 0000000000..83ec24dec8 --- /dev/null +++ b/test/files/neg/not-possible-cause.scala @@ -0,0 +1,3 @@ +object Foo { + def foo[A <: Product](a: A) { type X = a.type } +} diff --git a/test/files/neg/t3614.check b/test/files/neg/t3614.check index 5fdb5cbf1f..0f9c83aa0d 100644 --- a/test/files/neg/t3614.check +++ b/test/files/neg/t3614.check @@ -1,4 +1,4 @@ -t3614.scala:2: error: class type required but AnyRef{def a: <?>} found +t3614.scala:2: error: class type required but AnyRef{def a: Int} found def v = new ({ def a=0 }) ^ -one error found
\ No newline at end of file +one error found diff --git a/test/files/neg/t6263.check b/test/files/neg/t6263.check new file mode 100644 index 0000000000..9e9c7c615b --- /dev/null +++ b/test/files/neg/t6263.check @@ -0,0 +1,9 @@ +t6263.scala:5: error: type mismatch; + found : A.this.c.type (with underlying type C) + required: AnyRef +Note that C extends Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + type t = c.type + ^ +one error found diff --git a/test/files/neg/t6263.scala b/test/files/neg/t6263.scala new file mode 100644 index 0000000000..6575185b5c --- /dev/null +++ b/test/files/neg/t6263.scala @@ -0,0 +1,6 @@ +class C(val a: Any) extends AnyVal +class A { + implicit def c2AnyRef(c: C): AnyRef = new {} + val c = new C(0) + type t = c.type +} diff --git a/test/files/neg/t900.check b/test/files/neg/t900.check index ff5304a135..6fe26a31ac 100644 --- a/test/files/neg/t900.check +++ b/test/files/neg/t900.check @@ -1,6 +1,9 @@ t900.scala:4: error: type mismatch; found : Foo.this.x.type (with underlying type Foo.this.bar) required: AnyRef +Note that bar is unbounded, which means AnyRef is not a known parent. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. def break(): x.type ^ one error found diff --git a/test/files/run/reflection-equality.check b/test/files/run/reflection-equality.check index be531fbbd3..17c1f6dd70 100644 --- a/test/files/run/reflection-equality.check +++ b/test/files/run/reflection-equality.check @@ -1,53 +1,53 @@ -Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala>
-
-scala> class X {
- def methodIntIntInt(x: Int, y: Int) = x+y
-}
-defined class X
-
-scala>
-
-scala> import scala.reflect.runtime.universe._
-import scala.reflect.runtime.universe._
-
-scala> import scala.reflect.runtime.{ currentMirror => cm }
-import scala.reflect.runtime.{currentMirror=>cm}
-
-scala> def im: InstanceMirror = cm.reflect(new X)
-im: reflect.runtime.universe.InstanceMirror
-
-scala> val cs: ClassSymbol = im.symbol
-cs: reflect.runtime.universe.ClassSymbol = class X
-
-scala> val ts: Type = cs.typeSignature
-ts: reflect.runtime.universe.Type =
-java.lang.Object {
- def <init>: <?>
- def methodIntIntInt: <?>
-}
-
-scala> val ms: MethodSymbol = ts.declaration(newTermName("methodIntIntInt")).asMethod
-ms: reflect.runtime.universe.MethodSymbol = method methodIntIntInt
-
-scala> val MethodType( _, t1 ) = ms.typeSignature
-t1: reflect.runtime.universe.Type = scala.Int
-
-scala> val t2 = typeOf[scala.Int]
-t2: reflect.runtime.universe.Type = Int
-
-scala> t1 == t2
-res0: Boolean = false
-
-scala> t1 =:= t2
-res1: Boolean = true
-
-scala> t1 <:< t2
-res2: Boolean = true
-
-scala> t2 <:< t1
-res3: Boolean = true
-
-scala>
+Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> class X { + def methodIntIntInt(x: Int, y: Int) = x+y +} +defined class X + +scala> + +scala> import scala.reflect.runtime.universe._ +import scala.reflect.runtime.universe._ + +scala> import scala.reflect.runtime.{ currentMirror => cm } +import scala.reflect.runtime.{currentMirror=>cm} + +scala> def im: InstanceMirror = cm.reflect(new X) +im: reflect.runtime.universe.InstanceMirror + +scala> val cs: ClassSymbol = im.symbol +cs: reflect.runtime.universe.ClassSymbol = class X + +scala> val ts: Type = cs.typeSignature +ts: reflect.runtime.universe.Type = +java.lang.Object { + def <init>(): X + def methodIntIntInt(x: scala.Int,y: scala.Int): scala.Int +} + +scala> val ms: MethodSymbol = ts.declaration(newTermName("methodIntIntInt")).asMethod +ms: reflect.runtime.universe.MethodSymbol = method methodIntIntInt + +scala> val MethodType( _, t1 ) = ms.typeSignature +t1: reflect.runtime.universe.Type = scala.Int + +scala> val t2 = typeOf[scala.Int] +t2: reflect.runtime.universe.Type = Int + +scala> t1 == t2 +res0: Boolean = false + +scala> t1 =:= t2 +res1: Boolean = true + +scala> t1 <:< t2 +res2: Boolean = true + +scala> t2 <:< t1 +res3: Boolean = true + +scala> diff --git a/test/files/run/t5256a.check b/test/files/run/t5256a.check index 518663b3da..7e60139db3 100644 --- a/test/files/run/t5256a.check +++ b/test/files/run/t5256a.check @@ -1,6 +1,6 @@ -class A
-A
+class A +A Object { - def <init>: <?> - def foo: <?> -}
+ def <init>(): A + def foo: Nothing +} diff --git a/test/files/run/t5256b.check b/test/files/run/t5256b.check index d6015f2743..a80df6eb30 100644 --- a/test/files/run/t5256b.check +++ b/test/files/run/t5256b.check @@ -1,6 +1,6 @@ -class A
-Test.A
+class A +Test.A Object { - def <init>: <?> - def foo: <?> -}
+ def <init>(): Test.A + def foo: Nothing +} diff --git a/test/files/run/t5256d.check b/test/files/run/t5256d.check index dd32c05a93..9742ae572e 100644 --- a/test/files/run/t5256d.check +++ b/test/files/run/t5256d.check @@ -1,32 +1,32 @@ -Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala>
-
-scala> import scala.reflect.runtime.universe._
-import scala.reflect.runtime.universe._
-
-scala> import scala.reflect.runtime.{currentMirror => cm}
-import scala.reflect.runtime.{currentMirror=>cm}
-
-scala> class A { def foo = ??? }
-defined class A
-
-scala> val c = cm.classSymbol(classOf[A])
-c: reflect.runtime.universe.ClassSymbol = class A
-
-scala> println(c)
-class A
-
-scala> println(c.fullName)
-$line8.$read.$iw.$iw.$iw.$iw.A
-
-scala> println(c.typeSignature)
-java.lang.Object {
- def <init>: <?>
- def foo: <?>
-}
-
-scala>
-
-scala>
+Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> import scala.reflect.runtime.universe._ +import scala.reflect.runtime.universe._ + +scala> import scala.reflect.runtime.{currentMirror => cm} +import scala.reflect.runtime.{currentMirror=>cm} + +scala> class A { def foo = ??? } +defined class A + +scala> val c = cm.classSymbol(classOf[A]) +c: reflect.runtime.universe.ClassSymbol = class A + +scala> println(c) +class A + +scala> println(c.fullName) +$line8.$read.$iw.$iw.$iw.$iw.A + +scala> println(c.typeSignature) +java.lang.Object { + def <init>(): A + def foo: scala.Nothing +} + +scala> + +scala> diff --git a/test/files/run/t5256e.check b/test/files/run/t5256e.check index 6c6de90acc..011115720c 100644 --- a/test/files/run/t5256e.check +++ b/test/files/run/t5256e.check @@ -1,6 +1,6 @@ class A Test.C.A Object { - def <init>: <?> - def foo: <?> + def <init>(): C.this.A + def foo: Nothing } diff --git a/test/files/run/t5256f.check b/test/files/run/t5256f.check index c840793fd5..e0fec85596 100644 --- a/test/files/run/t5256f.check +++ b/test/files/run/t5256f.check @@ -1,12 +1,12 @@ class A1 Test.A1 Object { - def <init>: <?> - def foo: <?> + def <init>(): Test.A1 + def foo: Nothing } class A2 Test.A2 Object { - def <init>: <?> - def foo: <?> + def <init>(): Test.this.A2 + def foo: Nothing } |