From a4faf441711afcccaffb2329bc409139c604eb4c Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Wed, 20 Jun 2007 12:51:39 +0000 Subject: fixed bug1188 fix kind-checking in adapt: it checked tree.symbol.typeParams, which makes m[t] look like a higher-kinded type, even though it's of kind * (the symbol doesn't know about the application to t)... now using tree.tpe.typeParams removed check for tree.hasSymbol (TypeTree's must also be checked, and they don't directly have a symbol) replaced tree.symbol by tree.tpe.symbol --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 13 +++++++++---- test/files/neg/wellkinded_wrongarity.check | 2 +- test/files/neg/wellkinded_wrongarity2.check | 15 ++++++++++++--- test/files/neg/wellkinded_wrongarity2.scala | 10 +++++++++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index b80170a302..7e486c3439 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -625,17 +625,22 @@ trait Typers { self: Analyzer => } else if (tree.hasSymbol && !tree.symbol.typeParams.isEmpty && (mode & HKmode) == 0) { // (7) // @M When not typing a higher-kinded type ((mode & HKmode) == 0), types must be of kind *, // and thus parameterised types must be applied to their type arguments + // @M TODO: why do kind-* tree's have symbols, while higher-kinded ones don't? errorTree(tree, tree.symbol+" takes type parameters") tree setType tree.tpe - } else if (tree.hasSymbol && ((mode & HKmode) != 0) && // (7.1) @M: check kind-arity - tree.symbol.typeParams.length != pt.typeParams.length && - !(tree.symbol==AnyClass || tree.symbol==AllClass || pt == WildcardType )) { + } else if ( // (7.1) @M: check kind-arity + // @M: removed check for tree.hasSymbol and replace tree.symbol by tree.tpe.symbol (TypeTree's must also be checked here, and they don't directly have a symbol) + ((mode & HKmode) != 0) && + // @M: don't check tree.tpe.symbol.typeParams. check tree.tpe.typeParams!!! + // (e.g., m[Int] --> tree.tpe.symbol.typeParams.length == 1, tree.tpe.typeParams.length == 0!) + tree.tpe.typeParams.length != pt.typeParams.length && + !(tree.tpe.symbol==AnyClass || tree.tpe.symbol==AllClass || pt == WildcardType )) { // Check that the actual kind arity (tree.symbol.typeParams.length) conforms to the expected // kind-arity (pt.typeParams.length). Full checks are done in checkKindBounds in Infer. // Note that we treat Any and Nothing as kind-polymorphic. // We can't perform this check when typing type arguments to an overloaded method before the overload is resolved // (or in the case of an error type) -- this is indicated by pt == WildcardType (see case TypeApply in typed1). - errorTree(tree, tree.symbol+" takes "+reporter.countElementsAsString(tree.symbol.typeParams.length, "type parameter")+ + errorTree(tree, tree.tpe+" takes "+reporter.countElementsAsString(tree.tpe.typeParams.length, "type parameter")+ ", expected: "+reporter.countAsString(pt.typeParams.length)) tree setType tree.tpe } else tree match { // (6) diff --git a/test/files/neg/wellkinded_wrongarity.check b/test/files/neg/wellkinded_wrongarity.check index 548b5e40bb..1dc38db5c1 100644 --- a/test/files/neg/wellkinded_wrongarity.check +++ b/test/files/neg/wellkinded_wrongarity.check @@ -1,4 +1,4 @@ -wellkinded_wrongarity.scala:5: error: type Pair takes two type parameters, expected: one +wellkinded_wrongarity.scala:5: error: Pair takes two type parameters, expected: one object mp extends Monad[Pair] ^ one error found diff --git a/test/files/neg/wellkinded_wrongarity2.check b/test/files/neg/wellkinded_wrongarity2.check index 353d2368a1..922f73381e 100644 --- a/test/files/neg/wellkinded_wrongarity2.check +++ b/test/files/neg/wellkinded_wrongarity2.check @@ -1,4 +1,13 @@ -wellkinded_wrongarity2.scala:4: error: type String takes no type parameters, expected: one -object ms extends Monad[String] +wellkinded_wrongarity2.scala:5: error: String takes no type parameters, expected: one +trait ms1 extends Monad[String] // wrong ^ -one error found +wellkinded_wrongarity2.scala:6: error: t takes no type parameters, expected: one +trait ms2[t] extends Monad[t] // wrong + ^ +wellkinded_wrongarity2.scala:7: error: m[t] takes no type parameters, expected: one +trait ms3[m[_], t] extends Monad[m[t]] // wrong -- added to check regression on bug + ^ +wellkinded_wrongarity2.scala:12: error: type m takes type parameters +trait Bar2[m[_]] extends Foo[m] // check that m is properly recognized as kind *->*, while * is expected + ^ +four errors found diff --git a/test/files/neg/wellkinded_wrongarity2.scala b/test/files/neg/wellkinded_wrongarity2.scala index ee9d771aaa..3154732672 100644 --- a/test/files/neg/wellkinded_wrongarity2.scala +++ b/test/files/neg/wellkinded_wrongarity2.scala @@ -1,4 +1,12 @@ // test well-kindedness checks + +// expecting types of kind *->* class Monad[m[x]] +trait ms1 extends Monad[String] // wrong +trait ms2[t] extends Monad[t] // wrong +trait ms3[m[_], t] extends Monad[m[t]] // wrong -- added to check regression on bug -object ms extends Monad[String] \ No newline at end of file +// expecting types of kind * +trait Foo[x] +trait Bar1[m[_]] extends Foo[m[Int]] // check that m[Int] is properly recognized as kind-* +trait Bar2[m[_]] extends Foo[m] // check that m is properly recognized as kind *->*, while * is expected \ No newline at end of file -- cgit v1.2.3