Skip to content

Update docs to the new semantics of inline parameters #10208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/reference/metaprogramming/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ private def sumExpr(argsExpr: Expr[Seq[Int]])(using QuoteContext): Expr[Int] = a

#### Quoted patterns

Quoted pattens allow to deconstruct complex code that contains a precise structure, types or methods.
Quoted pattens allow deconstructing complex code that contains a precise structure, types or methods.
Patterns `'{ ... }` can be placed in any location where Scala expects a pattern.

For example
Expand Down
24 changes: 1 addition & 23 deletions docs/docs/reference/metaprogramming/tasty-reflect.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ the scope where it is used.
```scala
import scala.quoted._

inline def natConst(x: => Int): Int = ${natConstImpl('{x})}
inline def natConst(inline x: Int): Int = ${natConstImpl('{x})}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to change the title of the doc to AST Reflect, as it's done in the code to avoid obscure terms to programmers and it is more accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it in the next docs update PR


def natConstImpl(x: Expr[Int])(using qctx: QuoteContext): Expr[Int] = {
import qctx.reflect._
Expand Down Expand Up @@ -66,28 +66,6 @@ The method `qctx.reflect.Term.seal` provides a way to go back to a
must be set explicitly with a checked `cast` call. If the type does not conform
to it an exception will be thrown at runtime.

### Obtaining the underlying argument

A macro can access the tree of the actual argument passed on the call-site. The
`underlyingArgument` method on a `Term` object will give access to the tree
defining the expression passed. For example the code below matches a selection
operation expression passed while calling the `macro` below.

```scala
inline def macro(param: => Boolean): Unit = ${ macroImpl('param) }

def macroImpl(param: Expr[Boolean])(using qctx: QuoteContext): Expr[Unit] = {
import qctx.reflect._
import util._

param.unseal.underlyingArgument match {
case t @ Apply(Select(lhs, op), rhs :: Nil) => ..
}
}

// example
macro(this.checkCondition())
```

### Positions

Expand Down