Skip to content

Commit 9b8db9f

Browse files
authored
Harden tpd.Apply/TypeApply in case of errors (#16887)
Harden tpd.Apply/TypeApply in case of errors to accept non-sensical terms as functions. Fixes #16861
2 parents 2421437 + d6ee51e commit 9b8db9f

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
4747
Apply(expr, args)
4848
case _: RefTree | _: GenericApply | _: Inlined | _: Hole =>
4949
ta.assignType(untpd.Apply(fn, args), fn, args)
50+
case _ =>
51+
assert(ctx.reporter.errorsReported)
52+
ta.assignType(untpd.Apply(fn, args), fn, args)
5053

5154
def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = fn match
5255
case Block(Nil, expr) =>
5356
TypeApply(expr, args)
5457
case _: RefTree | _: GenericApply =>
5558
ta.assignType(untpd.TypeApply(fn, args), fn, args)
59+
case _ =>
60+
assert(ctx.reporter.errorsReported)
61+
ta.assignType(untpd.TypeApply(fn, args), fn, args)
5662

5763
def Literal(const: Constant)(using Context): Literal =
5864
ta.assignType(untpd.Literal(const))

tests/neg/i16861.scala

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
given foo[T]: Any = summon[bar] // error
2+
def bar: Nothing = ???

tests/neg/i16861a.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import scala.quoted.*
2+
trait Foo
3+
object Foo:
4+
inline given foo[T <: Foo]: T = summon[Type.of[T]] // error

0 commit comments

Comments
 (0)