Skip to content

Fix #941 #960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/dotty/tools/dotc/reporting/ConsoleReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
Expand Down
22 changes: 20 additions & 2 deletions src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions test/dotc/scala-collections.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i941.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object Test {

def bar(tl: => String) = {
val x = tl _ //error
val y = x _ // error
val s: String = x() // error
}

}
10 changes: 10 additions & 0 deletions tests/pos/i941.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object Test {

class C[A] {

def this(y: A) = { this(); foo(y) }

def foo(x: A): Unit = ()

}
}