From c4181de5eb0fd4e2f03a67d3e1c7a13dd90c2860 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Tue, 15 May 2007 22:58:06 +0000 Subject: fixed bug1112 --- src/compiler/scala/tools/nsc/doc/ModelToXML.scala | 2 +- src/compiler/scala/tools/nsc/symtab/Definitions.scala | 2 +- src/compiler/scala/tools/nsc/symtab/Types.scala | 5 +++-- test/files/neg/bug1112.check | 4 ++++ test/files/neg/bug1112.scala | 14 ++++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 test/files/neg/bug1112.check create mode 100644 test/files/neg/bug1112.scala diff --git a/src/compiler/scala/tools/nsc/doc/ModelToXML.scala b/src/compiler/scala/tools/nsc/doc/ModelToXML.scala index 85e6e117a6..234b640546 100644 --- a/src/compiler/scala/tools/nsc/doc/ModelToXML.scala +++ b/src/compiler/scala/tools/nsc/doc/ModelToXML.scala @@ -35,7 +35,7 @@ trait ModelToXML extends ModelExtractor { def link(tpe: Type)(implicit frame: Frame): NodeSeq = { if (!tpe.typeArgs.isEmpty) { if (definitions.isFunctionType(tpe)) { - val (args,r) = tpe.typeArgs.splitAt(tpe.typeArgs.length - 1); + val (args,r) = tpe.normalize.typeArgs.splitAt(tpe.normalize.typeArgs.length - 1); args.mkXML("(", ", ", ")")(link) ++ Text(" => ") ++ link(r.head); } else if (tpe.symbol == definitions.RepeatedParamClass) { assert(tpe.typeArgs.length == 1); diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index a7f40f84ec..6c663d4e8c 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -299,7 +299,7 @@ trait Definitions { case MethodType(delegateParams, delegateReturn) => val delegateParamsO = delegateParams.map(pt => {if (pt == definitions.AnyClass.tpe) definitions.ObjectClass.tpe else pt}) if (isFunctionType(functionType)) - functionType match { + functionType.normalize match { case TypeRef(_, _, args) => if (delegateParamsO == args.dropRight(1) && delegateReturn == args.last) diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 26134d0087..60e39bcebf 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -1242,8 +1242,9 @@ A type's symbol should never be inspected directly. override def normalize = if (sym.isAliasType) { - if (sym.info.typeParams.length == args.length || !sym.info.isComplete) // beta-reduce -- check if the info has been loaded, if not, the arity check is meaningless + if (sym.info.typeParams.length == args.length) // beta-reduce -- check if the info has been loaded, if not, the arity check is meaningless // Martin to Adriaan: I believe sym.info.isComplete is redundant here + // @M: correct: it was a remnant of a previous fix for the problem in the last else {} branch transform(sym.info.resultType).normalize // cycles have been checked in typeRef else if (isHigherKinded) PolyType(typeParams, transform(sym.info.resultType).normalize) @@ -1303,7 +1304,7 @@ A type's symbol should never be inspected directly. if (sym == ByNameParamClass && !args.isEmpty) return "=> " + args(0).toString() if (isFunctionType(this)) - return args.init.mkString("(", ", ", ")") + " => " + args.last + return normalize.typeArgs.init.mkString("(", ", ", ")") + " => " + normalize.typeArgs.last if (isTupleType(this)) return args.mkString("(", ", ", if (args.length == 1) ",)" else ")") } diff --git a/test/files/neg/bug1112.check b/test/files/neg/bug1112.check new file mode 100644 index 0000000000..3be45a87fe --- /dev/null +++ b/test/files/neg/bug1112.check @@ -0,0 +1,4 @@ +bug1112.scala:12: error: wrong number of arguments for method call: (int)(=> () => unit)unit + call(0,() => System.out.println("here we are")) + ^ +one error found diff --git a/test/files/neg/bug1112.scala b/test/files/neg/bug1112.scala new file mode 100644 index 0000000000..3e108e39af --- /dev/null +++ b/test/files/neg/bug1112.scala @@ -0,0 +1,14 @@ +// checks that error doesn't crash the compiler +// (due to isFunctionType normalizing Type1 to a function type, +// but then the code that used that test not using the normalized type for further operations) +class Test { + type Type1 = () => unit + + def call(p: int)(f: => Type1) = { + f() + } + + def run = { + call(0,() => System.out.println("here we are")) + } +} \ No newline at end of file -- cgit v1.2.3