diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 26 | ||||
-rw-r--r-- | test/files/neg/t742.check | 5 | ||||
-rw-r--r-- | test/files/neg/t742.scala | 8 |
3 files changed, 24 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 15c5fb6c0e..9e10d3a408 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -394,9 +394,10 @@ trait Types extends reflect.generic.Types { self: SymbolTable => /** Replace formal type parameter symbols with actual type arguments. * - * Amounts to substitution except for higher-kinded types. (See overridden method in TypeRef) -- @M (contact adriaan.moors at cs.kuleuven.be) + * Amounts to substitution except for higher-kinded types. (See overridden method in TypeRef) -- @M */ - def instantiateTypeParams(formals: List[Symbol], actuals: List[Type]): Type = this.subst(formals, actuals) + def instantiateTypeParams(formals: List[Symbol], actuals: List[Type]): Type = + if(formals.length == actuals.length) this.subst(formals, actuals) else ErrorType /** If this type is an existential, turn all existentially bound variables to type skolems. * @param owner The owner of the created type skolems @@ -1706,8 +1707,9 @@ A type's typeSymbol should never be inspected directly. if (substTps.length == typeParams.length) typeRef(pre, sym, actuals) - else // partial application (needed in infer when bunching type arguments from classes and methods together) + else if(formals.length == actuals.length) // partial application (needed in infer when bunching type arguments from classes and methods together) typeRef(pre, sym, dummyArgs).subst(formals, actuals) + else ErrorType } else super.instantiateTypeParams(formals, actuals) @@ -1726,21 +1728,15 @@ A type's typeSymbol should never be inspected directly. if (sym == clazz && !args.isEmpty) args.head else this def normalize0: Type = - if (sym.isAliasType) { // beta-reduce - if (sym.info.typeParams.length == args.length || !isHigherKinded) { - /* !isHigherKinded && sym.info.typeParams.length != args.length only happens when compiling e.g., - `val x: Class' with -Xgenerics, while `type Class = java.lang.Class' had already been compiled without -Xgenerics */ - val xform = transform(sym.info.resultType) - assert(xform ne this, this) - xform.normalize // cycles have been checked in typeRef - } else { // should rarely happen, if at all - PolyType(sym.info.typeParams, transform(sym.info.resultType).normalize) // eta-expand -- for regularity, go through sym.info for typeParams - // @M TODO: should not use PolyType, as that's the type of a polymorphic value -- we really want a type *function* - } - } else if (isHigherKinded) { + if (isHigherKinded) { // @M TODO: should not use PolyType, as that's the type of a polymorphic value -- we really want a type *function* // @M: initialize (by sym.info call) needed (see test/files/pos/ticket0137.scala) PolyType(sym.info.typeParams, typeRef(pre, sym, dummyArgs)) // must go through sym.info for typeParams + } else if (sym.isAliasType) { // beta-reduce + if(sym.info.typeParams.length == args.length) // don't do partial application + transform(sym.info.resultType).normalize // cycles have been checked in typeRef + else + ErrorType } else if (sym.isRefinementClass) { sym.info.normalize // @MO to AM: OK? //@M I think this is okay, but changeset 12414 (which fixed #1241) re-introduced another bug (#2208) diff --git a/test/files/neg/t742.check b/test/files/neg/t742.check new file mode 100644 index 0000000000..f587948ef1 --- /dev/null +++ b/test/files/neg/t742.check @@ -0,0 +1,5 @@ +t742.scala:5: error: kinds of the type arguments (Crash._1,Crash._2,Any) do not conform to the expected kinds of the type parameters (type m,type n,type z). +Crash._1's type parameters do not match type m's expected parameters: type s1 has one type parameter, but type n has two + type p = mul[_1, _2, Any] // mul[_1, _1, Any] needs -Yrecursion + ^ +one error found diff --git a/test/files/neg/t742.scala b/test/files/neg/t742.scala new file mode 100644 index 0000000000..bb1c2f85ea --- /dev/null +++ b/test/files/neg/t742.scala @@ -0,0 +1,8 @@ +object Crash { + type mul[m[n[s[_], z], z], n[s[_], z], z] = m[n, z] + type _1[s1[_], z1] = s1[z1] + type _2[s1[_], z1] = s1[z1] + type p = mul[_1, _2, Any] // mul[_1, _1, Any] needs -Yrecursion + // _1[_2, Zero] + // _2[Zero] +}
\ No newline at end of file |