Skip to content

Commit 661ed61

Browse files
authored
Merge pull request #5190 from dotty-staging/fix-5107
Fix #5107: disallow block as Apply.fun
2 parents 2f64743 + 9616be1 commit 661ed61

File tree

8 files changed

+27
-148
lines changed

8 files changed

+27
-148
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ class Compiler {
6969
new ExplicitOuter, // Add accessors to outer classes from nested ones.
7070
new ExplicitSelf, // Make references to non-trivial self types explicit as casts
7171
new StringInterpolatorOpt, // Optimizes raw and s string interpolators by rewriting them to string concatentations
72-
new CrossCastAnd, // Normalize selections involving intersection types.
73-
new Splitter) :: // Expand selections involving union types into conditionals
72+
new CrossCastAnd) :: // Normalize selections involving intersection types.
7473
List(new PruneErasedDefs, // Drop erased definitions from scopes and simplify erased expressions
7574
new VCInlineMethods, // Inlines calls to value class methods
7675
new SeqLiterals, // Express vararg arguments as arrays

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
4040
def Super(qual: Tree, mixName: TypeName, inConstrCall: Boolean, mixinClass: Symbol = NoSymbol)(implicit ctx: Context): Super =
4141
Super(qual, if (mixName.isEmpty) untpd.EmptyTypeIdent else untpd.Ident(mixName), inConstrCall, mixinClass)
4242

43-
def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply =
43+
def Apply(fn: Tree, args: List[Tree])(implicit ctx: Context): Apply = {
44+
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]])
4445
ta.assignType(untpd.Apply(fn, args), fn, args)
46+
}
4547

46-
def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply =
48+
def TypeApply(fn: Tree, args: List[Tree])(implicit ctx: Context): TypeApply = {
49+
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply[_]])
4750
ta.assignType(untpd.TypeApply(fn, args), fn, args)
51+
}
4852

4953
def Literal(const: Constant)(implicit ctx: Context): Literal =
5054
ta.assignType(untpd.Literal(const))
@@ -181,8 +185,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
181185
def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative =
182186
ta.assignType(untpd.Alternative(trees), trees)
183187

184-
def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree], proto: Type)(implicit ctx: Context): UnApply =
188+
def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree], proto: Type)(implicit ctx: Context): UnApply = {
189+
assert(fun.isInstanceOf[RefTree] || fun.isInstanceOf[GenericApply[_]])
185190
ta.assignType(untpd.UnApply(fun, implicits, patterns), proto)
191+
}
186192

187193
def ValDef(sym: TermSymbol, rhs: LazyTree = EmptyTree)(implicit ctx: Context): ValDef =
188194
ta.assignType(untpd.ValDef(sym.name, TypeTree(sym.info), rhs), sym)

compiler/src/dotty/tools/dotc/transform/ElimByName.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class ElimByName extends TransformByNameApply with InfoTransformer {
3636

3737
override def phaseName: String = ElimByName.name
3838

39-
override def runsAfterGroupsOf: Set[String] = Set(Splitter.name)
40-
// I got errors running this phase in an earlier group, but I did not track them down.
41-
4239
override def changesParents: Boolean = true // Only true for by-names
4340

4441
/** Map `tree` to `tree.apply()` is `ftree` was of ExprType and becomes now a function */

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Erasure extends Phase with DenotTransformer {
3434
override def phaseName: String = Erasure.name
3535

3636
/** List of names of phases that should precede this phase */
37-
override def runsAfter: Set[String] = Set(InterceptedMethods.name, Splitter.name, ElimRepeated.name)
37+
override def runsAfter: Set[String] = Set(InterceptedMethods.name, ElimRepeated.name)
3838

3939
override def changesMembers: Boolean = true // the phase adds bridges
4040
override def changesParents: Boolean = true // the phase drops Any

compiler/src/dotty/tools/dotc/transform/Splitter.scala

Lines changed: 0 additions & 137 deletions
This file was deleted.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,12 @@ class Typer extends Namer
23652365
}
23662366
} else issueErrors()
23672367
}
2368-
else readaptSimplified(tpd.Apply(tree, args))
2368+
else tree match {
2369+
case tree: Block =>
2370+
readaptSimplified(tpd.Block(tree.stats, tpd.Apply(tree.expr, args)))
2371+
case _ =>
2372+
readaptSimplified(tpd.Apply(tree, args))
2373+
}
23692374
}
23702375
addImplicitArgs(argCtx(tree))
23712376
}

compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import vulpix.TestConfiguration
1717
class PatmatExhaustivityTest {
1818
val testsDir = "tests/patmat"
1919
// stop-after: patmatexhaust-huge.scala crash compiler
20-
val options = List("-color:never", "-Ystop-after:splitter", "-Ycheck-all-patmat", "-classpath", TestConfiguration.basicClasspath)
20+
val options = List("-color:never", "-Ystop-after:crossCast", "-Ycheck-all-patmat", "-classpath", TestConfiguration.basicClasspath)
2121

2222
private def compileFile(path: JPath) = {
2323
val stringBuffer = new StringWriter()

tests/pos/i5107.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Test {
2+
inline def foo(x: Int = 5)(implicit y: Int): Int =
3+
if (x > 0) y * y
4+
else y + y
5+
6+
implicit val m: Int = 7
7+
8+
(new Test).foo()
9+
}

0 commit comments

Comments
 (0)