Skip to content

Commit 6b061b5

Browse files
committed
Merge pull request #960 from dotty-staging/fix-#941
Fix #941
2 parents 08b5324 + 2c18740 commit 6b061b5

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ object Denotations {
320320
try info1 & info2
321321
catch {
322322
case ex: MergeError =>
323-
if (pre.widen.classSymbol.is(Scala2x))
323+
if (pre.widen.classSymbol.is(Scala2x) || ctx.scala2Mode)
324324
info1 // follow Scala2 linearization -
325325
// compare with way merge is performed in SymDenotation#computeMembersNamed
326326
else

src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class ConsoleReporter(
4747
printMessageAndPos(s"error: ${d.msg}", d.pos)
4848
if (ctx.settings.prompt.value) displayPrompt()
4949
case d: ConditionalWarning if !d.enablingOption.value =>
50+
case d: MigrationWarning =>
51+
printMessageAndPos(s"migration warning: ${d.msg}", d.pos)
5052
case d: Warning =>
5153
printMessageAndPos(s"warning: ${d.msg}", d.pos)
5254
case _ =>

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
909909
val DefDef(name, tparams, vparamss, tpt, _) = ddef
910910
completeAnnotations(ddef, sym)
911911
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
912+
// for secondary constructors we need to use that their type parameters
913+
// are aliases of the class type parameters. See pos/i941.scala
914+
if (sym.isConstructor && !sym.isPrimaryConstructor)
915+
(sym.owner.typeParams, tparams1).zipped.foreach {(tparam, tdef) =>
916+
tdef.symbol.info = TypeAlias(tparam.typeRef)
917+
}
918+
912919
val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef])
913920
if (sym is Implicit) checkImplicitParamsNotSingletons(vparamss1)
914921
val tpt1 = checkSimpleKinded(typedType(tpt))
@@ -1044,8 +1051,19 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10441051
}
10451052
}
10461053

1047-
def typedAsFunction(tree: untpd.Tree, pt: Type)(implicit ctx: Context): Tree =
1048-
typed(tree, if (defn.isFunctionType(pt)) pt else AnyFunctionProto)
1054+
def typedAsFunction(tree: untpd.Tree, pt: Type)(implicit ctx: Context): Tree = {
1055+
val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto
1056+
var res = typed(tree, pt1)
1057+
if (pt1.eq(AnyFunctionProto) && !defn.isFunctionClass(res.tpe.classSymbol)) {
1058+
def msg = i"not a function: ${res.tpe}; cannot be followed by `_'"
1059+
if (ctx.scala2Mode) {
1060+
ctx.migrationWarning(msg, tree.pos)
1061+
res = typed(untpd.Function(Nil, untpd.TypedSplice(res)))
1062+
}
1063+
else ctx.error(msg, tree.pos)
1064+
}
1065+
res
1066+
}
10491067

10501068
/** Retrieve symbol attached to given tree */
10511069
protected def retrieveSym(tree: untpd.Tree)(implicit ctx: Context) = tree.removeAttachment(SymOfTree) match {

test/dotc/scala-collections.whitelist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,12 @@
232232
./scala-scala/src/library/scala/collection/immutable/SetProxy.scala
233233

234234
# https://github.com/lampepfl/dotty/issues/942
235-
# ./scala-scala/src/library/scala/collection/immutable/SortedMap.scala
236-
#./scala-scala/src/library/scala/collection/immutable/SortedSet.scala
235+
./scala-scala/src/library/scala/collection/immutable/SortedMap.scala
236+
./scala-scala/src/library/scala/collection/immutable/SortedSet.scala
237237

238238
# https://github.com/lampepfl/dotty/issues/941
239-
#./scala-scala/src/library/scala/collection/immutable/Stream.scala
240-
#./scala-scala/src/library/scala/collection/immutable/StreamView.scala
239+
./scala-scala/src/library/scala/collection/immutable/Stream.scala
240+
./scala-scala/src/library/scala/collection/immutable/StreamView.scala
241241

242242
./scala-scala/src/library/scala/collection/immutable/TreeMap.scala
243243
./scala-scala/src/library/scala/collection/immutable/TreeSet.scala

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class tests extends CompilerTest {
151151
@Test def neg_i0248_inherit_refined = compileFile(negDir, "i0248-inherit-refined", xerrors = 4)
152152
@Test def neg_i0281 = compileFile(negDir, "i0281-null-primitive-conforms", xerrors = 3)
153153
@Test def neg_i583 = compileFile(negDir, "i0583-skolemize", xerrors = 2)
154+
@Test def neg_i941 = compileFile(negDir, "i941", xerrors = 3)
154155
@Test def neg_finalSealed = compileFile(negDir, "final-sealed", xerrors = 2)
155156
@Test def neg_i705 = compileFile(negDir, "i705-inner-value-class", xerrors = 7)
156157
@Test def neg_i866 = compileFile(negDir, "i866", xerrors = 2)

tests/neg/i941.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
3+
def bar(tl: => String) = {
4+
val x = tl _ //error
5+
val y = x _ // error
6+
val s: String = x() // error
7+
}
8+
9+
}

tests/pos/i941.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Test {
2+
3+
class C[A] {
4+
5+
def this(y: A) = { this(); foo(y) }
6+
7+
def foo(x: A): Unit = ()
8+
9+
}
10+
}

0 commit comments

Comments
 (0)