Skip to content

Fix #2514: Survive non-sensical trees in Typer #2752

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 4 commits into from
Jun 14, 2017
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ object desugar {
def enumTagMeths = if (isEnumCase) enumTagMeth(CaseKind.Class)._1 :: Nil else Nil
def copyMeths = {
def isRepeated(tree: Tree): Boolean = tree match {
case PostfixOp(_, Ident(nme.raw.STAR)) => true
case PostfixOp(_, Ident(tpnme.raw.STAR)) => true
case ByNameTypeTree(tree1) => isRepeated(tree1)
case _ => false
}
Expand Down Expand Up @@ -1051,7 +1051,7 @@ object desugar {
else // l.op(r), or val x = r; l.op(x), plus handle named args specially
makeBinop(l, op, r)
case PostfixOp(t, op) =>
if ((ctx.mode is Mode.Type) && !op.isBackquoted && op.name == nme.raw.STAR) {
if ((ctx.mode is Mode.Type) && !op.isBackquoted && op.name == tpnme.raw.STAR) {
val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType
Annotated(
AppliedTypeTree(ref(seqType), t),
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
* parameter, the reference will be a repeated argument.
*/
def refOfDef(tree: MemberDef)(implicit ctx: Context) = tree match {
case ValDef(_, PostfixOp(_, Ident(nme.raw.STAR)), _) => repeated(Ident(tree.name))
case ValDef(_, PostfixOp(_, Ident(tpnme.raw.STAR)), _) => repeated(Ident(tree.name))
case _ => Ident(tree.name)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ object JavaParsers {
if (in.token == DOTDOTDOT) {
in.nextToken()
t = atPos(t.pos.start) {
PostfixOp(t, Ident(nme.raw.STAR))
PostfixOp(t, Ident(tpnme.raw.STAR))
}
}
atPos(start, in.offset) {
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ object Parsers {
val t = toplevelTyp()
if (isIdent(nme.raw.STAR)) {
in.nextToken()
atPos(startOffset(t)) { PostfixOp(t, Ident(nme.raw.STAR)) }
atPos(startOffset(t)) { PostfixOp(t, Ident(tpnme.raw.STAR)) }
} else t
}

Expand Down Expand Up @@ -1322,7 +1322,7 @@ object Parsers {
* | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')'
*
* Special treatment for arguments of primary class constructor
* annotations. All empty argument lists `(` `)` following the first
* annotations. All empty argument lists `(` `)` following the first
* get represented as `List(ParamNotArg)` instead of `Nil`, indicating that
* the token sequence should be interpreted as an empty parameter clause
* instead. `ParamNotArg` can also be produced when parsing the first
Expand Down Expand Up @@ -2047,7 +2047,7 @@ object Parsers {

private def checkVarArgsRules(vparamss: List[List[untpd.ValDef]]): List[untpd.ValDef] = {
def isVarArgs(tpt: Trees.Tree[Untyped]): Boolean = tpt match {
case PostfixOp(_, op) if op.name == nme.raw.STAR => true
case PostfixOp(_, op) if op.name == tpnme.raw.STAR => true
case _ => false
}

Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
throw ex
}
case _ =>
assert(isFullyDefined(pt, ForceDegree.none))
tree.withType(pt)
tree.withType(
if (isFullyDefined(pt, ForceDegree.none)) pt else UnspecifiedErrorType)
}
}

Expand Down Expand Up @@ -1124,7 +1124,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
tparam.ensureCompleted()
case _ =>
}
typed(desugaredArg, argPt)
if (desugaredArg.isType) typed(desugaredArg, argPt)
else desugaredArg.withType(UnspecifiedErrorType)
}
args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]]
}
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/i2514.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object Foo {
def foo(): Int = {
val f: implicit Int => Int = (implicit x: Int) => 2 * x // error // error
f(2)
}

val f = (implicit x: Int) => x // error // error

((implicit x: Int) => x): (implicit Int => Int) // error // error // error
}
17 changes: 17 additions & 0 deletions tests/pos/Result.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import scala.util.control.NonFatal
object p {

enum Result[+T, +E] {
case OK [T](x: T) extends Result[T, Nothing]
case Err[E](e: E) extends Result[Nothing, E]
}

type Try[T] = Result[T, Throwable]
object Try {
def apply[T](x: => T): Try[T] =
try Result.OK(x)
catch {
case NonFatal(ex) => Result.Err(ex)
}
}
}