Skip to content

Commit

Permalink
Fix possible crash in Desugar
Browse files Browse the repository at this point in the history
This might fix #19560.

[Cherry-picked 6e31578]
  • Loading branch information
odersky authored and WojciechMazur committed Jun 28, 2024
1 parent 733a794 commit fc34a41
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1502,15 +1502,17 @@ object desugar {
* skipping elements that are not convertible.
*/
def patternsToParams(elems: List[Tree])(using Context): List[ValDef] =
def toParam(elem: Tree, tpt: Tree): Tree =
def toParam(elem: Tree, tpt: Tree, span: Span): Tree =
elem match
case Annotated(elem1, _) => toParam(elem1, tpt)
case Typed(elem1, tpt1) => toParam(elem1, tpt1)
case Ident(id: TermName) => ValDef(id, tpt, EmptyTree).withFlags(Param)
case Annotated(elem1, _) => toParam(elem1, tpt, span)
case Typed(elem1, tpt1) => toParam(elem1, tpt1, span)
case Ident(id: TermName) => ValDef(id, tpt, EmptyTree).withFlags(Param).withSpan(span)
case _ => EmptyTree
elems.map(param => toParam(param, TypeTree()).withSpan(param.span)).collect {
case vd: ValDef => vd
}
elems
.map: param =>
toParam(param, TypeTree(), param.span)
.collect:
case vd: ValDef => vd

def makeContextualFunction(formals: List[Tree], body: Tree, erasedParams: List[Boolean])(using Context): Function = {
val mods = Given
Expand Down

0 comments on commit fc34a41

Please sign in to comment.