Skip to content

Commit

Permalink
Backport "Fix #18649: Use loBound of param types when materializing a…
Browse files Browse the repository at this point in the history
… context function." to LTS (#20645)

Backports #18651 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur committed Jun 20, 2024
2 parents 517a604 + 70ecf1a commit 998d994
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,14 @@ object TreeChecker {
super.typedClassDef(cdef, cls)
}

override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree =
val tpdTree = super.typedValDef(vdef, sym)
vdef.tpt.tpe match
case _: ValueType => () // ok
case _: ExprType if sym.isOneOf(TermParamOrAccessor) => () // ok
case _ => assert(false, i"wrong type, expected a value type for ${sym.fullName}, but found: ${sym.info}")
tpdTree

override def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(using Context): Tree =
def defParamss = ddef.paramss.filter(!_.isEmpty).nestedMap(_.symbol)
def layout(symss: List[List[Symbol]]): String =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3160,7 +3160,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(untpd.TypeTree)
else formals.map(formal => untpd.TypeTree(formal.loBound)) // about loBound, see tests/pos/i18649.scala
}

val erasedParams = pt match {
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i18649.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test:
// always inferred Nothing for `x`
def contextFunctionWildcardExplicit: ? ?=> String = x ?=> "foo"

// used to infer TYPEBOUNDS for the type of the argument
def contextFunctionWildcardInserted: ? ?=> String = "foo"
end Test

0 comments on commit 998d994

Please sign in to comment.