From c34ac1c9c4ad93c780105a3842de0f969b7923cb Mon Sep 17 00:00:00 2001 From: odersky Date: Wed, 10 Apr 2024 18:40:05 +0200 Subject: [PATCH] Make parameter types of synthesized context functions inferred type trees A non-sensical capture reference appeared in the type of a synthesized context function literal. We do clean out @retains annotations that can contain such references, but only for inferred type trees. The problem was that context function parameters were treated like explicitly given types before. Fixes #20135 --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- tests/pos/i20135.scala | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i20135.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 7c278505f38b..612bd22ef19d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3271,7 +3271,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer val paramTypes = { val hasWildcard = formals.exists(_.existsPart(_.isInstanceOf[WildcardType], StopAt.Static)) if hasWildcard then formals.map(_ => untpd.TypeTree()) - else formals.map(formal => untpd.TypeTree(formal.loBound)) // about loBound, see tests/pos/i18649.scala + else formals.map(formal => untpd.InferredTypeTree(formal.loBound)) // about loBound, see tests/pos/i18649.scala } val erasedParams = pt match { diff --git a/tests/pos/i20135.scala b/tests/pos/i20135.scala new file mode 100644 index 000000000000..6143d642fbbb --- /dev/null +++ b/tests/pos/i20135.scala @@ -0,0 +1,11 @@ +import language.experimental.captureChecking + +class Network + +class Page(using nw: Network^): + def render(client: Page^{nw} ?-> Unit) = client(using this) + +def main(net: Network^) = + var page = Page(using net) + page.render(()) +