Skip to content

Commit 8ddfcaf

Browse files
authored
Merge pull request #2752 from dotty-staging/fix-#2514-2
Fix #2514: Survive non-sensical trees in Typer
2 parents 2520992 + 696bb4b commit 8ddfcaf

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ object desugar {
380380
def enumTagMeths = if (isEnumCase) enumTagMeth(CaseKind.Class)._1 :: Nil else Nil
381381
def copyMeths = {
382382
def isRepeated(tree: Tree): Boolean = tree match {
383-
case PostfixOp(_, Ident(nme.raw.STAR)) => true
383+
case PostfixOp(_, Ident(tpnme.raw.STAR)) => true
384384
case ByNameTypeTree(tree1) => isRepeated(tree1)
385385
case _ => false
386386
}
@@ -1051,7 +1051,7 @@ object desugar {
10511051
else // l.op(r), or val x = r; l.op(x), plus handle named args specially
10521052
makeBinop(l, op, r)
10531053
case PostfixOp(t, op) =>
1054-
if ((ctx.mode is Mode.Type) && !op.isBackquoted && op.name == nme.raw.STAR) {
1054+
if ((ctx.mode is Mode.Type) && !op.isBackquoted && op.name == tpnme.raw.STAR) {
10551055
val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType
10561056
Annotated(
10571057
AppliedTypeTree(ref(seqType), t),

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
367367
* parameter, the reference will be a repeated argument.
368368
*/
369369
def refOfDef(tree: MemberDef)(implicit ctx: Context) = tree match {
370-
case ValDef(_, PostfixOp(_, Ident(nme.raw.STAR)), _) => repeated(Ident(tree.name))
370+
case ValDef(_, PostfixOp(_, Ident(tpnme.raw.STAR)), _) => repeated(Ident(tree.name))
371371
case _ => Ident(tree.name)
372372
}
373373

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ object JavaParsers {
447447
if (in.token == DOTDOTDOT) {
448448
in.nextToken()
449449
t = atPos(t.pos.start) {
450-
PostfixOp(t, Ident(nme.raw.STAR))
450+
PostfixOp(t, Ident(tpnme.raw.STAR))
451451
}
452452
}
453453
atPos(start, in.offset) {

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ object Parsers {
916916
val t = toplevelTyp()
917917
if (isIdent(nme.raw.STAR)) {
918918
in.nextToken()
919-
atPos(startOffset(t)) { PostfixOp(t, Ident(nme.raw.STAR)) }
919+
atPos(startOffset(t)) { PostfixOp(t, Ident(tpnme.raw.STAR)) }
920920
} else t
921921
}
922922

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

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

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10561056
throw ex
10571057
}
10581058
case _ =>
1059-
assert(isFullyDefined(pt, ForceDegree.none))
1060-
tree.withType(pt)
1059+
tree.withType(
1060+
if (isFullyDefined(pt, ForceDegree.none)) pt else UnspecifiedErrorType)
10611061
}
10621062
}
10631063

@@ -1124,7 +1124,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11241124
tparam.ensureCompleted()
11251125
case _ =>
11261126
}
1127-
typed(desugaredArg, argPt)
1127+
if (desugaredArg.isType) typed(desugaredArg, argPt)
1128+
else desugaredArg.withType(UnspecifiedErrorType)
11281129
}
11291130
args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]]
11301131
}

tests/neg/i2514.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Foo {
2+
def foo(): Int = {
3+
val f: implicit Int => Int = (implicit x: Int) => 2 * x // error // error
4+
f(2)
5+
}
6+
7+
val f = (implicit x: Int) => x // error // error
8+
9+
((implicit x: Int) => x): (implicit Int => Int) // error // error // error
10+
}

tests/pos/Result.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.util.control.NonFatal
2+
object p {
3+
4+
enum Result[+T, +E] {
5+
case OK [T](x: T) extends Result[T, Nothing]
6+
case Err[E](e: E) extends Result[Nothing, E]
7+
}
8+
9+
type Try[T] = Result[T, Throwable]
10+
object Try {
11+
def apply[T](x: => T): Try[T] =
12+
try Result.OK(x)
13+
catch {
14+
case NonFatal(ex) => Result.Err(ex)
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)