diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 666908fabd0e..b6519e1cd9da 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -320,7 +320,7 @@ object Denotations { try info1 & info2 catch { case ex: MergeError => - if (pre.widen.classSymbol.is(Scala2x)) + if (pre.widen.classSymbol.is(Scala2x) || ctx.scala2Mode) info1 // follow Scala2 linearization - // compare with way merge is performed in SymDenotation#computeMembersNamed else diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index 3e2aaa88011e..45268b6735fe 100644 --- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -47,6 +47,8 @@ class ConsoleReporter( printMessageAndPos(s"error: ${d.msg}", d.pos) if (ctx.settings.prompt.value) displayPrompt() case d: ConditionalWarning if !d.enablingOption.value => + case d: MigrationWarning => + printMessageAndPos(s"migration warning: ${d.msg}", d.pos) case d: Warning => printMessageAndPos(s"warning: ${d.msg}", d.pos) case _ => diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 10bca44bfb27..d54c9f7314ba 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -909,6 +909,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val DefDef(name, tparams, vparamss, tpt, _) = ddef completeAnnotations(ddef, sym) val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef]) + // for secondary constructors we need to use that their type parameters + // are aliases of the class type parameters. See pos/i941.scala + if (sym.isConstructor && !sym.isPrimaryConstructor) + (sym.owner.typeParams, tparams1).zipped.foreach {(tparam, tdef) => + tdef.symbol.info = TypeAlias(tparam.typeRef) + } + val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef]) if (sym is Implicit) checkImplicitParamsNotSingletons(vparamss1) val tpt1 = checkSimpleKinded(typedType(tpt)) @@ -1044,8 +1051,19 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - def typedAsFunction(tree: untpd.Tree, pt: Type)(implicit ctx: Context): Tree = - typed(tree, if (defn.isFunctionType(pt)) pt else AnyFunctionProto) + def typedAsFunction(tree: untpd.Tree, pt: Type)(implicit ctx: Context): Tree = { + val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto + var res = typed(tree, pt1) + if (pt1.eq(AnyFunctionProto) && !defn.isFunctionClass(res.tpe.classSymbol)) { + def msg = i"not a function: ${res.tpe}; cannot be followed by `_'" + if (ctx.scala2Mode) { + ctx.migrationWarning(msg, tree.pos) + res = typed(untpd.Function(Nil, untpd.TypedSplice(res))) + } + else ctx.error(msg, tree.pos) + } + res + } /** Retrieve symbol attached to given tree */ protected def retrieveSym(tree: untpd.Tree)(implicit ctx: Context) = tree.removeAttachment(SymOfTree) match { diff --git a/test/dotc/scala-collections.whitelist b/test/dotc/scala-collections.whitelist index 826da6da2e2c..6c4a34f0e359 100644 --- a/test/dotc/scala-collections.whitelist +++ b/test/dotc/scala-collections.whitelist @@ -232,12 +232,12 @@ ./scala-scala/src/library/scala/collection/immutable/SetProxy.scala # https://github.com/lampepfl/dotty/issues/942 -# ./scala-scala/src/library/scala/collection/immutable/SortedMap.scala -#./scala-scala/src/library/scala/collection/immutable/SortedSet.scala +./scala-scala/src/library/scala/collection/immutable/SortedMap.scala +./scala-scala/src/library/scala/collection/immutable/SortedSet.scala # https://github.com/lampepfl/dotty/issues/941 -#./scala-scala/src/library/scala/collection/immutable/Stream.scala -#./scala-scala/src/library/scala/collection/immutable/StreamView.scala +./scala-scala/src/library/scala/collection/immutable/Stream.scala +./scala-scala/src/library/scala/collection/immutable/StreamView.scala ./scala-scala/src/library/scala/collection/immutable/TreeMap.scala ./scala-scala/src/library/scala/collection/immutable/TreeSet.scala diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 1bd37125f41f..22981b8378c2 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -151,6 +151,7 @@ class tests extends CompilerTest { @Test def neg_i0248_inherit_refined = compileFile(negDir, "i0248-inherit-refined", xerrors = 4) @Test def neg_i0281 = compileFile(negDir, "i0281-null-primitive-conforms", xerrors = 3) @Test def neg_i583 = compileFile(negDir, "i0583-skolemize", xerrors = 2) + @Test def neg_i941 = compileFile(negDir, "i941", xerrors = 3) @Test def neg_finalSealed = compileFile(negDir, "final-sealed", xerrors = 2) @Test def neg_i705 = compileFile(negDir, "i705-inner-value-class", xerrors = 7) @Test def neg_i866 = compileFile(negDir, "i866", xerrors = 2) diff --git a/tests/neg/i941.scala b/tests/neg/i941.scala new file mode 100644 index 000000000000..2643c2546b2c --- /dev/null +++ b/tests/neg/i941.scala @@ -0,0 +1,9 @@ +object Test { + + def bar(tl: => String) = { + val x = tl _ //error + val y = x _ // error + val s: String = x() // error + } + +} diff --git a/tests/pos/i941.scala b/tests/pos/i941.scala new file mode 100644 index 000000000000..75bf4e4482a7 --- /dev/null +++ b/tests/pos/i941.scala @@ -0,0 +1,10 @@ +object Test { + + class C[A] { + + def this(y: A) = { this(); foo(y) } + + def foo(x: A): Unit = () + + } +}