Skip to content
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

Expr#show: Don't crash when the expression contains an unsupported type (like a SkolemType) #20494

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -177,6 +177,8 @@ object Extractors {
this += "Alternatives(" ++= patterns += ")"
case TypedOrTest(tree, tpt) =>
this += "TypedOrTest(" += tree += ", " += tpt += ")"
case tree =>
this += s"<Internal compiler AST $tree does not have a corresponding reflect extractor>"
}

def visitConstant(x: Constant): this.type = x match {
@@ -241,6 +243,8 @@ object Extractors {
this += "MatchCase(" += pat += ", " += rhs += ")"
case FlexibleType(tp) =>
this += "FlexibleType(" += tp += ")"
case tp =>
this += s"<Internal compiler type $tp does not have a corresponding reflect extractor>"
}

def visitSignature(sig: Signature): this.type = {
Original file line number Diff line number Diff line change
@@ -1292,7 +1292,9 @@ object SourceCode {
val sym = annot.tpe.typeSymbol
sym != Symbol.requiredClass("scala.forceInline") &&
sym.maybeOwner != Symbol.requiredPackage("scala.annotation.internal")
case x => cannotBeShownAsSource(x.show(using Printer.TreeStructure))
case x =>
cannotBeShownAsSource(x.show(using Printer.TreeStructure))
false
}
printAnnotations(annots)
if (annots.nonEmpty) this += " "
@@ -1463,8 +1465,8 @@ object SourceCode {
}
}

private def cannotBeShownAsSource(x: String): Nothing =
throw new Exception(s"$x does not have a source representation")
private def cannotBeShownAsSource(x: String): this.type =
this += s"<$x does not have a source representation>"

private object SpecialOp {
def unapply(arg: Tree): Option[(String, List[Term])] = arg match {
10 changes: 10 additions & 0 deletions tests/pos-macros/skolem/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.quoted.*

object Macro {

def impl(expr: Expr[Any])(using Quotes): Expr[Unit] =
println(expr.show)
'{ () }

inline def macr(inline x: Any): Unit = ${impl('x)}
}
9 changes: 9 additions & 0 deletions tests/pos-macros/skolem/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait Foo:
val x: Int
def ho(p: x.type => x.type): Unit = ()

object Test {
var f: Foo = ???
Macro.macr:
f.ho(arg => arg)
}
4 changes: 2 additions & 2 deletions tests/run-macros/i19905.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
java.lang.Exception: NoPrefix() does not have a source representation
java.lang.Exception: NoPrefix() does not have a source representation
<NoPrefix() does not have a source representation>
<NoPrefix() does not have a source representation>
NoPrefix()