Skip to content

Commit 74a8ef9

Browse files
committed
Merge pull request scala#1901 from paulp/pr/dealias-plus-annotations
dealiasing and annotations
2 parents baee5f3 + f01e001 commit 74a8ef9

30 files changed

+421
-199
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,14 +1584,9 @@ self =>
15841584
* }}}
15851585
*/
15861586
def argumentExprs(): List[Tree] = {
1587-
def args(): List[Tree] = commaSeparated {
1588-
val maybeNamed = isIdent
1589-
expr() match {
1590-
case a @ Assign(id, rhs) if maybeNamed =>
1591-
atPos(a.pos) { AssignOrNamedArg(id, rhs) }
1592-
case e => e
1593-
}
1594-
}
1587+
def args(): List[Tree] = commaSeparated(
1588+
if (isIdent) treeInfo.assignmentToMaybeNamedArg(expr()) else expr()
1589+
)
15951590
in.token match {
15961591
case LBRACE => List(blockExpr())
15971592
case LPAREN => inParens(if (in.token == RPAREN) Nil else args())

src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,10 @@ abstract class TreeBuilder {
171171

172172
/** Create tree representing (unencoded) binary operation expression or pattern. */
173173
def makeBinop(isExpr: Boolean, left: Tree, op: TermName, right: Tree, opPos: Position): Tree = {
174-
def mkNamed(args: List[Tree]) =
175-
if (isExpr) args map {
176-
case a @ Assign(id @ Ident(name), rhs) =>
177-
atPos(a.pos) { AssignOrNamedArg(id, rhs) }
178-
case e => e
179-
} else args
174+
def mkNamed(args: List[Tree]) = if (isExpr) args map treeInfo.assignmentToMaybeNamedArg else args
180175
val arguments = right match {
181176
case Parens(args) => mkNamed(args)
182-
case _ => List(right)
177+
case _ => List(right)
183178
}
184179
if (isExpr) {
185180
if (treeInfo.isLeftAssoc(op)) {

src/compiler/scala/tools/nsc/interpreter/IMain.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
521521
Right(buildRequest(line, trees))
522522
}
523523

524-
// normalize non-public types so we don't see protected aliases like Self
525-
def normalizeNonPublic(tp: Type) = tp match {
524+
// dealias non-public types so we don't see protected aliases like Self
525+
def dealiasNonPublic(tp: Type) = tp match {
526526
case TypeRef(_, sym, _) if sym.isAliasType && !sym.isPublic => tp.dealias
527527
case _ => tp
528528
}
@@ -980,7 +980,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
980980

981981
def cleanTypeAfterTyper(sym: => Symbol): Type = {
982982
exitingTyper(
983-
normalizeNonPublic(
983+
dealiasNonPublic(
984984
dropNullaryMethod(
985985
sym.tpe_*
986986
)

src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ abstract class ClassfileParser {
2929
protected var in: AbstractFileReader = _ // the class file reader
3030
protected var clazz: Symbol = _ // the class symbol containing dynamic members
3131
protected var staticModule: Symbol = _ // the module symbol containing static members
32-
protected var instanceScope: Scope = _ // the scope of all instance definitions
33-
protected var staticScope: Scope = _ // the scope of all static definitions
32+
protected var instanceScope: Scope = _ // the scope of all instance definitions
33+
protected var staticScope: Scope = _ // the scope of all static definitions
3434
protected var pool: ConstantPool = _ // the classfile's constant pool
3535
protected var isScala: Boolean = _ // does class file describe a scala class?
3636
protected var isScalaAnnot: Boolean = _ // does class file describe a scala class with its pickled info in an annotation?
@@ -739,15 +739,9 @@ abstract class ClassfileParser {
739739
// isMonomorphicType is false if the info is incomplete, as it usually is here
740740
// so have to check unsafeTypeParams.isEmpty before worrying about raw type case below,
741741
// or we'll create a boatload of needless existentials.
742-
else if (classSym.isMonomorphicType || classSym.unsafeTypeParams.isEmpty) {
743-
tp
744-
}
745-
else {
746-
// raw type - existentially quantify all type parameters
747-
val eparams = typeParamsToExistentials(classSym, classSym.unsafeTypeParams)
748-
val t = typeRef(pre, classSym, eparams.map(_.tpeHK))
749-
logResult(s"raw type from $classSym")(newExistentialType(eparams, t))
750-
}
742+
else if (classSym.isMonomorphicType || classSym.unsafeTypeParams.isEmpty) tp
743+
// raw type - existentially quantify all type parameters
744+
else logResult(s"raw type from $classSym")(definitions.unsafeClassExistentialType(classSym))
751745
case tp =>
752746
assert(sig.charAt(index) != '<', tp)
753747
tp

src/compiler/scala/tools/nsc/typechecker/Checkable.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ trait Checkable {
6262
bases foreach { bc =>
6363
val tps1 = (from baseType bc).typeArgs
6464
val tps2 = (tvarType baseType bc).typeArgs
65+
if (tps1.size != tps2.size)
66+
devWarning(s"Unequally sized type arg lists in propagateKnownTypes($from, $to): ($tps1, $tps2)")
67+
6568
(tps1, tps2).zipped foreach (_ =:= _)
6669
// Alternate, variance respecting formulation causes
6770
// neg/unchecked3.scala to fail (abstract types). TODO -
@@ -78,7 +81,7 @@ trait Checkable {
7881

7982
val resArgs = tparams zip tvars map {
8083
case (_, tvar) if tvar.instValid => tvar.constr.inst
81-
case (tparam, _) => tparam.tpe
84+
case (tparam, _) => tparam.tpeHK
8285
}
8386
appliedType(to, resArgs: _*)
8487
}
@@ -108,7 +111,7 @@ trait Checkable {
108111
private class CheckabilityChecker(val X: Type, val P: Type) {
109112
def Xsym = X.typeSymbol
110113
def Psym = P.typeSymbol
111-
def XR = propagateKnownTypes(X, Psym)
114+
def XR = if (Xsym == AnyClass) classExistentialType(Psym) else propagateKnownTypes(X, Psym)
112115
// sadly the spec says (new java.lang.Boolean(true)).isInstanceOf[scala.Boolean]
113116
def P1 = X matchesPattern P
114117
def P2 = !Psym.isPrimitiveValueClass && isNeverSubType(X, P)

src/compiler/scala/tools/nsc/typechecker/Infer.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ trait Infer extends Checkable {
244244
* This method seems to be performance critical.
245245
*/
246246
def normalize(tp: Type): Type = tp match {
247+
case pt @ PolyType(tparams, restpe) =>
248+
logResult(s"Normalizing $tp in infer")(normalize(restpe))
247249
case mt @ MethodType(params, restpe) if mt.isImplicit =>
248250
normalize(restpe)
249251
case mt @ MethodType(_, restpe) if !mt.isDependentMethodType =>
@@ -866,7 +868,7 @@ trait Infer extends Checkable {
866868
val (argtpes1, argPos, namesOK) = checkNames(argtpes0, params)
867869
// when using named application, the vararg param has to be specified exactly once
868870
( namesOK
869-
&& (isIdentity(argPos) || sameLength(formals, params))
871+
&& (allArgsArePositional(argPos) || sameLength(formals, params))
870872
&& typesCompatible(reorderArgs(argtpes1, argPos)) // nb. arguments and names are OK, check if types are compatible
871873
)
872874
}
@@ -1222,8 +1224,6 @@ trait Infer extends Checkable {
12221224
}
12231225
}
12241226

1225-
def widen(tp: Type): Type = abstractTypesToBounds(tp)
1226-
12271227
/** Substitute free type variables `undetparams` of type constructor
12281228
* `tree` in pattern, given prototype `pt`.
12291229
*
@@ -1232,7 +1232,7 @@ trait Infer extends Checkable {
12321232
* @param pt the expected result type of the instance
12331233
*/
12341234
def inferConstructorInstance(tree: Tree, undetparams: List[Symbol], pt0: Type) {
1235-
val pt = widen(pt0)
1235+
val pt = abstractTypesToBounds(pt0)
12361236
val ptparams = freeTypeParamsOfTerms(pt)
12371237
val ctorTp = tree.tpe
12381238
val resTp = ctorTp.finalResultType
@@ -1371,7 +1371,7 @@ trait Infer extends Checkable {
13711371
}
13721372

13731373
def inferTypedPattern(tree0: Tree, pattp: Type, pt0: Type, canRemedy: Boolean): Type = {
1374-
val pt = widen(pt0)
1374+
val pt = abstractTypesToBounds(pt0)
13751375
val ptparams = freeTypeParamsOfTerms(pt)
13761376
val tpparams = freeTypeParamsOfTerms(pattp)
13771377

src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ trait NamesDefaults { self: Analyzer =>
4141
blockTyper: Typer
4242
) { }
4343

44-
def nameOf(arg: Tree) = arg match {
45-
case AssignOrNamedArg(Ident(name), rhs) => Some(name)
46-
case _ => None
44+
private def nameOfNamedArg(arg: Tree) = Some(arg) collect { case AssignOrNamedArg(Ident(name), _) => name }
45+
def isNamedArg(arg: Tree) = arg match {
46+
case AssignOrNamedArg(Ident(_), _) => true
47+
case _ => false
4748
}
48-
def isNamed(arg: Tree) = nameOf(arg).isDefined
4949

5050
/** @param pos maps indices from old to new */
5151
def reorderArgs[T: ClassTag](args: List[T], pos: Int => Int): List[T] = {
@@ -55,13 +55,13 @@ trait NamesDefaults { self: Analyzer =>
5555
}
5656

5757
/** @param pos maps indices from new to old (!) */
58-
def reorderArgsInv[T: ClassTag](args: List[T], pos: Int => Int): List[T] = {
58+
private def reorderArgsInv[T: ClassTag](args: List[T], pos: Int => Int): List[T] = {
5959
val argsArray = args.toArray
6060
(argsArray.indices map (i => argsArray(pos(i)))).toList
6161
}
6262

6363
/** returns `true` if every element is equal to its index */
64-
def isIdentity(a: Array[Int]) = (0 until a.length).forall(i => a(i) == i)
64+
def allArgsArePositional(a: Array[Int]) = (0 until a.length).forall(i => a(i) == i)
6565

6666
/**
6767
* Transform a function application into a Block, and assigns typer.context
@@ -359,7 +359,7 @@ trait NamesDefaults { self: Analyzer =>
359359
}
360360
}
361361

362-
def missingParams[T](args: List[T], params: List[Symbol], argName: T => Option[Name] = nameOf _): (List[Symbol], Boolean) = {
362+
def missingParams[T](args: List[T], params: List[Symbol], argName: T => Option[Name] = nameOfNamedArg _): (List[Symbol], Boolean) = {
363363
val namedArgs = args.dropWhile(arg => {
364364
val n = argName(arg)
365365
n.isEmpty || params.forall(p => p.name != n.get)

0 commit comments

Comments
 (0)