Skip to content

Reject failed inits #4434

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

Closed
wants to merge 8 commits into from
Closed

Reject failed inits #4434

wants to merge 8 commits into from

Conversation

ankitson
Copy link
Contributor

@ankitson ankitson commented May 1, 2018

This is a fix for #4416 . Its still WIP, some cleanup & style fixes needed I think, but the basic idea is here so I thought I would open it up to suggestions.

@allanrenucci It mostly does what you suggested, except we also have to patch compile to account for failures in displayDefinitions.

It doesn't seem very clean, but it is explicit about the dependency between display and the REPL state. I think it will remain a little messy until we decouple eval and rendering.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@ankitson
Copy link
Contributor Author

ankitson commented May 1, 2018

Also found another weird behavior:

Without this patch:

scala> lazy val x = 1/0
val x: Int = <lazy>
scala> val y = x
java.lang.ArithmeticException: / by zero
	...
scala> y
java.lang.NoClassDefFoundError: Could not initialize class rs$line$2$
...
scala> x
val res1: Int = 0

With the patch:

scala> lazy val x = 1/0
val x: Int = <lazy>
scala> val y = x
java.lang.ArithmeticException: / by zero
	...
scala> y
1 |y
  |^
  |not found: y
scala> x
<rendering error>

Which seems better, maybe not ideal.

@allanrenucci allanrenucci self-assigned this May 7, 2018
).foreach(str => out.println(SyntaxHighlighting(str)))

state.copy(valIndex = state.valIndex - vals.filter(resAndUnit).length)
val (successes, failures) = vals.map(rendering.renderVal).partition(_.isSuccess)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should stop rendering vals after the first failure, like scalac REPL:

scala> val x = 1 / 0; println("1")
java.lang.ArithmeticException: / by zero
  ... 28 elided

In the example above, println("1") is not evaluated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And not render anything (e.g. aliases, methods) in case of failure

val resultValue =
if (d.symbol.is(Flags.Lazy)) Some("<lazy>")
else valueOf(d.symbol)

resultValue.map(value => s"$dcl = $value")
}
catch { case ex: InvocationTargetException => Some(renderError(ex)) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should propagate any exception that is not an InvocationTargetException

@allanrenucci allanrenucci assigned ankitson and unassigned allanrenucci Oct 2, 2018
@ankitson
Copy link
Contributor Author

ankitson commented Oct 19, 2018

@allanrenucci I managed to get this working. For some reason to do with classloaders I don't fully understand, the Rendering class gets into a bad state if we throw an exception while evaluating, and this happens:

scala> val x = 1/0
java.lang.ArithmeticException: / by zero
...
scala> val y = 1/0

scala> def f = y
def f: Int

My PR now creates a new Rendering upon failure.

@odersky
Copy link
Contributor

odersky commented Jan 12, 2019

@allanrenucci Since this was not re-assigned to you it probably fell through the cracks. Can you take a look and decide whether this can go in now? Thanks

@odersky odersky assigned allanrenucci and unassigned ankitson Jan 12, 2019
@OlivierBlanvillain
Copy link
Contributor

@ankitson Sorry for the long silence. Do still plan to work on this PR? The latest commits seems like a hack rather than a clean solution; a var with a scala.util.control.Breaks.{break, breakable}, we are not going to merge a diff like that...

@OlivierBlanvillain
Copy link
Contributor

Closing for now, feel free to reopen if you plan to further work on it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants