Skip to content

Commit 9cdfd12

Browse files
authored
Merge pull request #12213 from dotty-staging/fix-12207
Avoid crash in tpd.TypeApply
2 parents 351cb25 + c1fe160 commit 9cdfd12

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

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

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

44-
def Apply(fn: Tree, args: List[Tree])(using Context): Apply = {
45-
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply] || fn.isInstanceOf[Inlined] || fn.isInstanceOf[tasty.TreePickler.Hole])
46-
ta.assignType(untpd.Apply(fn, args), fn, args)
47-
}
48-
49-
def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = {
50-
assert(fn.isInstanceOf[RefTree] || fn.isInstanceOf[GenericApply])
51-
ta.assignType(untpd.TypeApply(fn, args), fn, args)
52-
}
44+
def Apply(fn: Tree, args: List[Tree])(using Context): Apply = fn match
45+
case Block(Nil, expr) =>
46+
Apply(expr, args)
47+
case _: RefTree | _: GenericApply | _: Inlined | _: tasty.TreePickler.Hole =>
48+
ta.assignType(untpd.Apply(fn, args), fn, args)
49+
50+
def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = fn match
51+
case Block(Nil, expr) =>
52+
TypeApply(expr, args)
53+
case _: RefTree | _: GenericApply =>
54+
ta.assignType(untpd.TypeApply(fn, args), fn, args)
5355

5456
def Literal(const: Constant)(using Context): Literal =
5557
ta.assignType(untpd.Literal(const))

tests/neg/i12207.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package example
2+
3+
extension [T](t: T) inline def pi[P <: Tuple](using P): T = ???
4+
5+
inline def env[P <: Tuple, T](op: P ?=> T): P ?=> T = op
6+
7+
@main def Test =
8+
env { pi[String] } // error // error

0 commit comments

Comments
 (0)