Skip to content

How to access showExtractors in M3? #10832

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

Closed
hmf opened this issue Dec 17, 2020 · 6 comments · Fixed by #10849
Closed

How to access showExtractors in M3? #10832

hmf opened this issue Dec 17, 2020 · 6 comments · Fixed by #10849

Comments

@hmf
Copy link

hmf commented Dec 17, 2020

Minimized code

  private def unsealUnderlying[T](p:Expr[T])(using t:Type[T], qctx:Quotes): Expr[T] = {
    import qctx.reflect._

    val xTree0: Term = Term.of(p)
    xTree0 match {
      case Inlined(_, _, _) =>  
        Term.of(p).underlying.asExprOf[T]
      case _ =>
        report.throwError(s"unsealUnderlying: Expected HList reference but got ${p.show} -- (${Term.of(p).showExtractors})", p)
    }
  }

  private def unsealUnderlying2[T](p:Expr[T])(using t:Type[T], qctx:Quotes): Expr[T] = {
    import qctx.reflect._

    val xTree0: Term = p.asTerm
    xTree0 match {
      case Inlined(_, _, _) =>  
        Term.of(p).underlying.asExprOf[T]
      case _ =>
        report.throwError(s"unsealUnderlying: Expected HList reference but got ${p.show} -- (${xTree0.showExtractors})", p)
    }
  }

Output

[error] 132 |        report.throwError(s"unsealUnderlying: Expected HList reference but got ${p.show} -- (${Term.of(p).showExtractors})", p)
[error]     |                                                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |             value showExtractors is not a member of qctx.reflect.Term

Expectation

To be able to show the extractor. I have searched the repo for showExtractors and only found the documentation here. No release note so were can I find an example?

Tested in the latest 3.0.0-M3

TIA

@bishabosha
Copy link
Member

I think this should work Printer.TreeStructure.show(xTree0)

@abgruszecki
Copy link
Contributor

@bishabosha you know, the polite thing to do is to wait until the person who raised the issue confirms that what you suggest actually solves their problem before you suddenly close the issue on them.

@bishabosha bishabosha reopened this Dec 17, 2020
@bishabosha
Copy link
Member

Oops, slip of the hand, @hmf does the snippet work for you? We should check to see if the documentation still mentions anywhere how to print extractors

@hmf
Copy link
Author

hmf commented Dec 17, 2020

@bishabosha Yes, I have just finished testing and it works. As for the documentation I did a search in the Github web interface and it only showed the source to this link:

https://dotty.epfl.ch/docs/reference/metaprogramming/tasty-reflect.html#extractors

Thank you

@bishabosha
Copy link
Member

yes it seems that https://github.com/lampepfl/dotty/blob/master/docs/docs/reference/metaprogramming/tasty-reflect.md should be updated to replace showExtractors with the new printing framework

@nicolasstucki
Copy link
Contributor

- tree.showExtractors
+ tree.show(using Printer.TreeStructure)

or

- tree.showExtractors
+ Printer.TreeStructure.show(tree)

or

- tree.showExtractors
+ given Printer[Tree] = Printer.TreeStructure
+ tree.show

Other printers are available in the same way under Printer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants