Scalatest: Scala 3 AST for PartialFunction

Created on 22 Jan 2021  路  5Comments  路  Source: scalatest/scalatest

@liufengyun @smarter I am trying to implement MatchPatternMacro with Scala 3 but it seems like when the Expr is PartialFunction I am unable to get the AST of the passed in PartialFunction, here's the minimal project for testing:

https://github.com/cheeseng/test-scala3-macro

Perhaps I am doing it wrongly? I need to get the AST for the passed in PartialFunction but what I got is just the Inlined AST that doesn't contain the AST of the given PartialFunction.

All 5 comments

You can try the following:

inline def apply(right: => PartialFunction[Any, _]) = ...
// or
inline def apply(inline right: PartialFunction[Any, _]) = ...

If I remember correctly, at least one of the above should work.

/cc @nicolasstucki : maybe inlining should not lift function literals?

@liufengyun The second approach with 'inline right' seems to work, I'll continue to try to get the macro to work using the second approach.

Thanks for the your help!

@liufengyun The MatchPatternMacro is implemented successfully! Got the ShouldMatchPatternSpec green, I shall close this ticket now.

Many thanks again for your help!

@liufengyun Just fyi this is the related commit:

https://github.com/cheeseng/scalatest/commit/fc8303ba2d81460179b0c2cd710f9176d9c35c0f

It is still in my fork's branch, I shall submit PR to scalatest repo as 3rd batch to improve Scala 3 support in ScalaTest.

@cheeseng Congrats on the excellent work 馃帀

Was this page helpful?
0 / 5 - 0 ratings