From d6ee51e3d4880737c3a9596bd3773ca5013db4f8 Mon Sep 17 00:00:00 2001 From: odersky Date: Sat, 11 Feb 2023 13:34:25 +0100 Subject: [PATCH] Harden tpd.Apply/TypeApply in case of errors Harden tpd.Apply/TypeApply in case of errors to accept non-sensical terms as functions. Fixes #16861 --- compiler/src/dotty/tools/dotc/ast/tpd.scala | 6 ++++++ tests/neg/i16861.scala | 2 ++ tests/neg/i16861a.scala | 4 ++++ 3 files changed, 12 insertions(+) create mode 100644 tests/neg/i16861.scala create mode 100644 tests/neg/i16861a.scala diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 1a202ece1e66..aea8cf297ab8 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -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)) diff --git a/tests/neg/i16861.scala b/tests/neg/i16861.scala new file mode 100644 index 000000000000..50c56974d027 --- /dev/null +++ b/tests/neg/i16861.scala @@ -0,0 +1,2 @@ +given foo[T]: Any = summon[bar] // error +def bar: Nothing = ??? \ No newline at end of file diff --git a/tests/neg/i16861a.scala b/tests/neg/i16861a.scala new file mode 100644 index 000000000000..b93f884f5e56 --- /dev/null +++ b/tests/neg/i16861a.scala @@ -0,0 +1,4 @@ +import scala.quoted.* +trait Foo +object Foo: + inline given foo[T <: Foo]: T = summon[Type.of[T]] // error