-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve message when tree cannot be shown as source (#19906)
Closes #19905
- Loading branch information
Showing
4 changed files
with
49 additions
and
7 deletions.
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,3 @@ | ||
java.lang.Exception: NoPrefix() does not have a source representation | ||
java.lang.Exception: NoPrefix() does not have a source representation | ||
NoPrefix() |
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,31 @@ | ||
import scala.quoted.* | ||
|
||
inline def noPrefixShortCode: String = | ||
${ noPrefixShortCodeImpl } | ||
|
||
inline def noPrefixCode: String = | ||
${ noPrefixCodeImpl } | ||
|
||
inline def noPrefixStructure: String = | ||
${ noPrefixStructure } | ||
|
||
def noPrefix(using Quotes): quotes.reflect.TypeRepr = | ||
import quotes.reflect.* | ||
TypeRepr.of[Unit] match | ||
case TypeRef(ThisType(TypeRef(prefix, _)), _) => prefix | ||
|
||
def noPrefixShortCodeImpl(using Quotes): Expr[String] = | ||
import quotes.reflect.* | ||
try Expr(Printer.TypeReprShortCode.show(noPrefix)) | ||
catch case ex: Exception => | ||
Expr(s"${ex.getClass.getName}: ${ex.getMessage}") | ||
|
||
def noPrefixCodeImpl(using Quotes): Expr[String] = | ||
import quotes.reflect.* | ||
try Expr(Printer.TypeReprCode.show(noPrefix)) | ||
catch case ex: Exception => | ||
Expr(s"${ex.getClass.getName}: ${ex.getMessage}") | ||
|
||
def noPrefixStructure(using Quotes): Expr[String] = | ||
import quotes.reflect.* | ||
Expr(Printer.TypeReprStructure.show(noPrefix)) |
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,5 @@ | ||
@main | ||
def Test: Unit = | ||
println(noPrefixShortCode) | ||
println(noPrefixCode) | ||
println(noPrefixStructure) |