forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid conversion of
Unit
type into ()
term
Fixes scala#20286
- Loading branch information
1 parent
e2c456f
commit 321881a
Showing
3 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import scala.quoted.* | ||
|
||
type P[+T] = ParsingRun[T] | ||
trait ParsingRun[+T] { | ||
var successValue: Any | ||
def freshSuccessUnit(): ParsingRun[Unit] | ||
|
||
} | ||
|
||
object MacroInlineImpls { | ||
inline def flatMapXInline[T, V]( | ||
lhs: ParsingRun[T] | ||
)(inline f: T => ParsingRun[V]): ParsingRun[V] = { | ||
f(lhs.successValue.asInstanceOf[T]) | ||
} | ||
|
||
def parsedSequence0[T: Type, V: Type, R: Type]( | ||
lhs: Expr[ParsingRun[T]], | ||
rhs: Expr[ParsingRun[V]] | ||
)(using quotes: Quotes): Expr[ParsingRun[R]] = { | ||
import quotes.reflect.* | ||
'{ $rhs.asInstanceOf[ParsingRun[R]] } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
implicit inline def LiteralStr(s: String)(implicit ctx: P[Any]): P[Unit] = ??? | ||
|
||
extension [T](inline parse0: P[T]) { | ||
inline def ~[V, R](inline other: P[V])(using | ||
ctx: P[?] | ||
): P[R] = ${ MacroInlineImpls.parsedSequence0[T, V, R]('parse0, 'other) } | ||
|
||
inline def flatMapX[V](inline f: T => P[V]): P[V] = | ||
MacroInlineImpls.flatMapXInline[T, V](parse0)(f) | ||
} | ||
|
||
def deeper[$: P]: P[Int] = ??? | ||
def newline[$: P]: P[Unit] = ??? | ||
def blockBody[p: P]: P[Seq[Int]] = newline ~ deeper.flatMapX { i => | ||
val y = LiteralStr("")(using ???) | ||
??? | ||
} |