-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #3703: Various fixes to make printing more robust in face of errors #3705
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,7 +196,12 @@ class PlainPrinter(_ctx: Context) extends Printer { | |
else toText(tp.origin) | ||
} | ||
case tp: LazyRef => | ||
"LazyRef(" ~ toTextGlobal(tp.ref) ~ ")" // TODO: only print this during debug mode? | ||
def refTxt = | ||
try toTextGlobal(tp.ref) | ||
catch { | ||
case ex: Throwable => Str("...") | ||
} | ||
"LazyRef(" ~ refTxt ~ ")" | ||
case _ => | ||
tp.fallbackToText(this) | ||
} | ||
|
@@ -217,7 +222,10 @@ class PlainPrinter(_ctx: Context) extends Printer { | |
|
||
/** If -uniqid is set, the hashcode of the lambda type, after a # */ | ||
protected def lambdaHash(pt: LambdaType): Text = | ||
if (ctx.settings.uniqid.value) "#" + pt.hashCode else "" | ||
if (ctx.settings.uniqid.value) | ||
try "#" + pt.hashCode | ||
catch { case ex: NullPointerException => "" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we do a null check first instead of catching NullPointerException ? This is fishy in general and is also not something that can be done on Scala.js by default (https://www.scala-js.org/doc/semantics.html) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, hashCode is computed, the null could be in a referenced type. |
||
else "" | ||
|
||
/** If -uniqid is set, the unique id of symbol, after a # */ | ||
protected def idString(sym: Symbol): String = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package bar { | ||
trait M[F[_]] | ||
class S[XS[_] <: M[XS], A](val x: XS[A]) | ||
object S { | ||
def apply[X[_] <: M[X], A](x: X[A]): S[X, A] = S[X, A](x) | ||
def unapply[X[_] <: M[X], A](p: S[X, A]): S[X, A] = S(p.x) | ||
} | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just to catch infinite loops in LazyRefs? If so I'd just catch StackOverflowException, though I think it'd be cleaner to do loop detection in
LazyRef#ref
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's to detect stack overflows. Evaluation of LazyRefs is not tail-recursive, so we will always get a stack overflow. Maybe we can do a better job in loop detection but I believe the two issues are separate.