Skip to content

Commit

Permalink
Harden tpd.Apply/TypeApply in case of errors (#16887)
Browse files Browse the repository at this point in the history
Harden tpd.Apply/TypeApply in case of errors to accept non-sensical
terms as functions.

Fixes #16861
  • Loading branch information
Kordyjan authored Feb 16, 2023
2 parents 2421437 + d6ee51e commit 9b8db9f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
Apply(expr, args)
case _: RefTree | _: GenericApply | _: Inlined | _: Hole =>
ta.assignType(untpd.Apply(fn, args), fn, args)
case _ =>
assert(ctx.reporter.errorsReported)
ta.assignType(untpd.Apply(fn, args), fn, args)

def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = fn match
case Block(Nil, expr) =>
TypeApply(expr, args)
case _: RefTree | _: GenericApply =>
ta.assignType(untpd.TypeApply(fn, args), fn, args)
case _ =>
assert(ctx.reporter.errorsReported)
ta.assignType(untpd.TypeApply(fn, args), fn, args)

def Literal(const: Constant)(using Context): Literal =
ta.assignType(untpd.Literal(const))
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/i16861.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
given foo[T]: Any = summon[bar] // error
def bar: Nothing = ???
4 changes: 4 additions & 0 deletions tests/neg/i16861a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import scala.quoted.*
trait Foo
object Foo:
inline given foo[T <: Foo]: T = summon[Type.of[T]] // error

0 comments on commit 9b8db9f

Please sign in to comment.