Skip to content

Commit

Permalink
Fix possible crash in Desugar (#19567)
Browse files Browse the repository at this point in the history
This might fix #19560.
  • Loading branch information
nicolasstucki authored Jan 30, 2024
2 parents 23efb89 + 6e31578 commit fb50b1e
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 @@ -1602,15 +1602,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], paramNamesOrNil: List[TermName], body: Tree, erasedParams: List[Boolean])(using Context): Function = {
val mods = Given
Expand Down

0 comments on commit fb50b1e

Please sign in to comment.