Skip to content

Undefined += in inner quote #6772

Closed
@nicolasstucki

Description

@nicolasstucki

Implementing scala.quoted.ExprOps.toExprOfList with

    /** Lifts this list of expressions into an expression of a list
     *
     *  Transforms a list of expression
     *    `e1 :: e2 :: ... :: Nil` where `ei: Expr[T]`
     *  to an expression equivalent to
     *    `'{ $e1 :: $e2 :: ... :: Nil }` typed as an `Expr[List[T]]`
     */
    def (list: List[Expr[T]]) toExprOfList[T] given Type[T], QuoteContext: Expr[List[T]] = '{
      val buff = List.newBuilder[T]
      ${ Expr.block(list.map(v => '{ buff +=  $v }), '{ buff.result() }) }
    }

fails with

35 |      ${ Expr.block(list.map(v => '{ buff `+=` $v }), '{ buff.result() }) }
   |                                     ^^^^^^^^^^^^
   |                                 undefined: buff.+= # 189467: TermRef(TermRef(NoPrefix,val buff),+=) at frontend
   | This location is in code that was inlined at quoted_2.scala:6

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions