summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2007-04-18 12:08:27 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2007-04-18 12:08:27 +0000
commit8625a87820eca3c40ee226d2df2f307eabb5378d (patch)
tree146120924eb8f516c254af2154807542a6517f74 /src
parentb1c47f7bfafc30f3ff2d4e7af7a56790cc8643de (diff)
downloadscala-8625a87820eca3c40ee226d2df2f307eabb5378d.tar.gz
scala-8625a87820eca3c40ee226d2df2f307eabb5378d.tar.bz2
scala-8625a87820eca3c40ee226d2df2f307eabb5378d.zip
fixed bug 1056: due to mixed use of normalized ...
fixed bug 1056: due to mixed use of normalized and non-normalized types should normalize types that were previously tested by a predicate that implicitly considered the normalized type. Before, given e.g., type X = Function[String, String], ``X''.isFunctionType was true (uses symbol, which normalizes), but ``X''.typeArgs.isEmpty (the alias doesn't have any type arguments) (there are probably more cases like this, for now looked for .typeArgs)
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala8
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
4 files changed, 13 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index de4c8c3fbb..c358188b38 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -1082,6 +1082,14 @@ trait Types {
}
override def symbol = if (sym.isAliasType) normalize.symbol else sym
+/* @MAT
+whenever you see `tp.symbol.isXXXX' and then act on tp based on that predicate, you're on thin ice,
+as `symbol' (and `prefix') automatically normalize, but the other inspectors don't.
+In other words, even if `tp.normalize.sym.isXXX' is true, `tp.sym.isXXX' may be false (if sym were a public method to access the non-normalized symbol)...
+
+In retrospect, I think `tp.symbol.isXXX' or (worse) `tp.symbol==XXX' should be replaced by `val tp = tp0.asXXX'.
+A type's symbol should never be inspected directly.
+*/
override def bounds: TypeBounds =
if (sym.isAbstractType) transform(thisInfo.bounds).asInstanceOf[TypeBounds]
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 18b757d981..a0ee58feab 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -45,7 +45,7 @@ trait Infer requires Analyzer {
case formal => formal
}
if (isVarArgs(formals1)) {
- val ft = formals1.last.typeArgs.head
+ val ft = formals1.last.normalize.typeArgs.head
formals1.init ::: (for (val i <- List.range(formals1.length - 1, nargs)) yield ft)
} else formals1
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 4bbd881cb5..969ab1cce2 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -793,7 +793,7 @@ trait Namers requires Analyzer {
if (elemtp =:= tp)
result = nested
else if (isFunctionType(tp) &&
- (!isFunctionType(elemtp) || tp.typeArgs.length > elemtp.typeArgs.length))
+ (!isFunctionType(elemtp) || tp.normalize.typeArgs.length > elemtp.normalize.typeArgs.length))
result = true
else (tp, elemtp) match {
case (TypeRef(pre, sym, args), TypeRef(elempre, elemsym, elemargs)) =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 7534df9bbb..38a7bcea62 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1314,14 +1314,14 @@ trait Typers requires Analyzer {
pt.symbol == PartialFunctionClass &&
fun.vparams.length == 1 && fun.body.isInstanceOf[Match])
&& // see bug901 for a reason why next conditions are neeed
- (pt.typeArgs.length - 1 == fun.vparams.length
+ (pt.normalize.typeArgs.length - 1 == fun.vparams.length
||
fun.vparams.exists(.tpt.isEmpty)))
- (pt.symbol, pt.typeArgs.init, pt.typeArgs.last)
+ (pt.symbol, pt.normalize.typeArgs.init, pt.normalize.typeArgs.last)
else
(FunctionClass(fun.vparams.length), fun.vparams map (x => NoType), WildcardType)
- val (clazz, argpts, respt) = decompose(if (codeExpected) pt.typeArgs.head else pt)
+ val (clazz, argpts, respt) = decompose(if (codeExpected) pt.normalize.typeArgs.head else pt)
if (fun.vparams.length != argpts.length)
errorTree(fun, "wrong number of parameters; expected = " + argpts.length)