The eagerly awaited companion commit to r23622, the surprise hit

of last winter.  Singletons now have the singleton type inferred in
monomorphic contexts as well.  In english:

  scala> object X
  defined module X

  scala> def f = X
  f: X.type

Wait, that's not english.  English review by moors.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25051 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2011-06-01 05:15:49 +00:00
parent daadd46d6d
commit e17ee363c1
4 changed files with 10 additions and 5 deletions

View File

@ -572,7 +572,7 @@ trait Infer {
tparam -> Some(
if (targ.typeSymbol == RepeatedParamClass) targ.baseType(SeqClass)
else if (targ.typeSymbol == JavaRepeatedParamClass) targ.baseType(ArrayClass)
else if (targ.typeSymbol.isModuleClass) targ // this infers Foo.type instead of "object Foo"
else if (targ.typeSymbol.isModuleClass) targ // this infers Foo.type instead of "object Foo" (see also widenIfNecessary)
else targ.widen
)
}

View File

@ -630,9 +630,14 @@ trait Namers { self: Analyzer =>
case _ =>
false
}
val tpe1 = tpe.deconst
val tpe2 = tpe1.widen
if (sym.isVariable || sym.isMethod && !sym.hasAccessorFlag)
// This infers Foo.type instead of "object Foo"
// See Infer#adjustTypeArgs for the polymorphic case.
if (tpe.typeSymbolDirect.isModuleClass) tpe1
else if (sym.isVariable || sym.isMethod && !sym.hasAccessorFlag)
if (tpe2 <:< pt) tpe2 else tpe1
else if (isHidden(tpe)) tpe2
// In an attempt to make pattern matches involving method local vals

View File

@ -370,5 +370,5 @@ plusOne: (x: Int)Int
res0: Int = 6
res1: java.lang.String = after reset
<console>:8: error: not found: value plusOne
plusOne(5) // should be undefined now
^
plusOne(5) // should be undefined now
^

View File

@ -1,4 +1,4 @@
t3507.scala:13: error: No Manifest available for object _1.b.c.
t3507.scala:13: error: No Manifest available for _1.b.c.type.
mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier
^
one error found