Skip to content

Commit

Permalink
Merge bee9d21 into dccfd7f
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed May 29, 2019
2 parents dccfd7f + bee9d21 commit e708346
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class WollokLauncher extends WollokChecker {
System.exit(0)
}
catch (Exception e) {
val stackTrace = e.stackTrace.map [ "\tat " + className + "." + methodName + " (" + fileName + ":" + lineNumber + ")" ].join("\n")
println("Error in Wollok Launcher => " + e.message + "\n" + stackTrace)
if (!e.class.simpleName.toUpperCase.startsWith("WOLLOK")) {
val stackTrace = e.stackTrace.map [ "\tat " + className + "." + methodName + " (" + fileName + ":" + lineNumber + ")" ].join("\n")
println("Error in Wollok Launcher => " + e.message + "\n" + stackTrace)
}
System.exit(-1)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.uqbar.project.wollok.tests.interpreter

import org.junit.Test

/**
* Tests for if conditions
*
* @author dodain
*/
class IfTestCase extends AbstractWollokInterpreterTestCase {

@Test
def void ifConditionAsANumber() {
'''
object numeroLoco {
method calculoLoco(n) {
if (n) {
return 0
}
return n
}
}
test "if condition as a number" {
assert.throwsExceptionWithMessage("Expression in 'if' must evaluate to a boolean. Instead got: 3 (Number)", { => numeroLoco.calculoLoco(3) })
}
'''.interpretPropagatingErrors
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class WollokInterpreter implements XInterpreter<EObject, WollokObject>, IWollokI
rootObject.generateStack
evaluator.evaluate(rootObject)
} catch (WollokProgramExceptionWrapper e) {
e.printStackTrace
throw e
} catch (Throwable e) {
e.printStackTrace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.uqbar.project.wollok.interpreter.api.XInterpreterEvaluator
import org.uqbar.project.wollok.interpreter.context.EvaluationContext
import org.uqbar.project.wollok.interpreter.context.UnresolvableReference
import org.uqbar.project.wollok.interpreter.core.CallableSuper
import org.uqbar.project.wollok.interpreter.core.WCallable
import org.uqbar.project.wollok.interpreter.core.WollokObject
import org.uqbar.project.wollok.interpreter.core.WollokProgramExceptionWrapper
import org.uqbar.project.wollok.interpreter.nativeobj.JavaWrapper
Expand Down Expand Up @@ -179,16 +178,14 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>
if (cond === null) {
throw newWollokExceptionAsJava(NLS.bind(Messages.WollokInterpreter_cannot_use_null_in_if, NULL))
}
if (!(cond.isWBoolean))
throw new WollokInterpreterException(
NLS.bind(Messages.WollokInterpreter_expression_in_if_must_evaluate_to_boolean, cond, cond?.class.name),
it)

if (wollokToJava(cond, Boolean) == Boolean.TRUE)
then.eval
else
^else?.eval
if (!(cond.isWBoolean)) {
throw newWollokExceptionAsJava(NLS.bind(Messages.WollokInterpreter_expression_in_if_must_evaluate_to_boolean, cond, cond?.behavior?.name))
}
if (wollokToJava(cond, Boolean) == Boolean.TRUE)
then.eval
else
^else?.eval
}

def dispatch WollokObject evaluate(WTry t) {
try
Expand Down

0 comments on commit e708346

Please sign in to comment.