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
Exceptions thrown with error.throwWithMessage
can not be catched
#963
Comments
There are at least 2 different issues here
>>> try { throw new Exception("foo") } catch e : Exception { }
null The piece of code doesn't produce any value, so ideally it shouldn't log anything. But still the execution semantic of the interpreter is right here. You are catching the same exception you are throwing. It must not pop to the repl.
This should be catched and it shouldn't pop the exception further. |
Yes, the issue I am reporting here is the latter - the first is an issue too, but is is non-blocking, and I think it happens with Just a hint: the second issue doesn't only happen in the REPL, but also though the wollok server, within a |
try { error.throwWithMessage("foo") } catch e : Exception { } While same line in Wollok program works fine, in REPL it throws an exception. rootObject: [org.uqbar.project.wollok.wollokDsl.impl.ImportImpl@4f3faa70 (importedNamespace: wollokREPL.*) that's for REPL
that works for a Program. I'll continue my research. |
Ok, problem is that in WollokInterpreterEvaluator def dispatch evaluate(WTry t) {
try
t.expression.eval
catch (WollokProgramExceptionWrapper e) {
val cach = t.catchBlocks.findFirst[ it.matches(e.wollokException) ]
if (cach != null) {
cach.evaluate(e)
} else
throw e
} finally
t.alwaysExpression?.eval
} It calls "matches" extension method: def boolean matches(WCatch cach, WollokObject it) {
cach.exceptionType == null || isKindOf(cach.exceptionType)
} and isKindOf is def isKindOf(WMethodContainer c) { behavior.isKindOf(c) } But... while in program they are the same class: In REPL they are different classes: So... this method return false, and an exception is thrown: def static dispatch isKindOf(WClass c1, WClass c2) {
WollokModelExtensions.isSuperTypeOf(c2, c1)
} WollokModelExtension def static boolean isSuperTypeOf(WClass a, WClass b) {
a == b || (b.parent != null && a.isSuperTypeOf(b.parent))
} But I don't get why... I feel like an economic analyst. |
Nice analysis !! Basically, WClasses equality is currently based on identity. And somehow on the REPL the base classes of wollok (SDK) are being loaded twice (or more times?). I would be good to understand the background fact that is loading SDK many times. def static boolean isSuperTypeOf(WClass a, WClass b) {
a == b || (b.parent != null && a.isSuperTypeOf(b.parent))
} Could be something like def static boolean isSuperTypeOf(WClass a, WClass b) {
a.fqn == b.fqn || (b.parent != null && a.isSuperTypeOf(b.parent))
} Notice the "fqn". I'm not sure but I believe that we have one extension method with that name somewhere. It gives you the full element name with package and all. |
👍 Yes, I was thinking that as a workaround, but now I'm more confident because you suggested so. Nevertheless I'll try to see what is going on here a little bit more. |
fqn is an valid extension method |
:) On Tue, Sep 6, 2016 at 10:18 PM, Fernando Dodino notifications@github.com
|
Well, I fighted and fighted, but I can't figure out where does Wollok create a second instance of Exception class. It happens only with error wko, throwing an error works, so I put a println line in every evaluation of WollokInterpreterEvaluator. Using fqn comparison it works perfect! Wollok interactive console (type "quit" to quit):
>>> try { error.throwWithMessage("foo") } catch e : Exception { console.println("jeje") }
jeje
>>> try { error.throwWithMessage("foo") } catch e : Exception { }
null
>>> try { throw new Exception("foo") } catch e : Exception { console.println("jeje") }
jeje |
Obviously, second example outputs null, it's not the desired behavior. But we should open a new issue for that. |
Fix #963 - FQN comparison for classes
See the following REPL session and compare how
throw
anderror.throwWithMessage
behave differently:I think that this has sometime worked, but I am not 100% confident about that.
Is this easy to fix? Is there any workaround to this bug? It is somewhat blocking for me since it breaks the mumuki console and prevents to run many exercises.
The text was updated successfully, but these errors were encountered: