wyvernlang / wyvern

The Wyvern programming language.
http://wyvernlang.github.io/
GNU General Public License v2.0
556 stars 65 forks source link

Fail to check incompatible types of the return values of if and else arms #351

Open sychoo opened 5 years ago

sychoo commented 5 years ago

The following code should throw an error stating that "if and else have incompatible types". However, it executes successfully.

require stdout  
def number(n:Int):Int
    if (n == 1)
        1
      else
        "other numbers"
stdout.printInt(number(1))

The following code should also throw an error stating that "if and else have incompatible types". However, there is a runtime error coming from the printInt function: "No applicable method "printInt"".

require stdout
def number(n:Int):Int
    if (n == 1)
        1
      else
        "other numbers"
stdout.printInt(number(2))

Exception in thread "main" java.lang.RuntimeException: no applicable method 'printInt'! at wyvern.tools.interop.JObject.invokeMethod(JObject.java:50) at wyvern.tools.interop.JavaValue.invoke(JavaValue.java:58) at wyvern.target.corewyvernIL.expression.MethodCall$1.interpret(MethodCall.java:167) at wyvern.target.corewyvernIL.expression.MethodCall.trampoline(MethodCall.java:183) at wyvern.target.corewyvernIL.expression.MethodCall.interpret(MethodCall.java:178) at wyvern.target.corewyvernIL.expression.SeqExpr.interpretCtx(SeqExpr.java:193) at wyvern.target.corewyvernIL.expression.SeqExpr.interpret(SeqExpr.java:224) at wyvern.tools.Interpreter.main(Interpreter.java:90)