Groenbech96 / J--Compiler-Implementation

MIT License
0 stars 0 forks source link

Type Checking - Conditional expressions (cond ? thenBranch : elseBranch ) #55

Closed Groenbech96 closed 4 years ago

Groenbech96 commented 4 years ago

Can someone confirm, maybe @Baizey that analyse is implemented for ternary ops?

  public JExpression analyze(Context context) {

    condition = condition.analyze(context);

    ifTrue = ifTrue.analyze(context);

    ifFalse = ifFalse.analyze(context);

    if (condition.type() != Type.BOOLEAN)
        JAST.compilationUnit.reportSemanticError(line(), "Ternary condition must evaluate to bool, evaluated to " + condition.type());

    if (ifTrue.type() != ifFalse.type())
        JAST.compilationUnit.reportSemanticError(line(), "Ternary cases must evaluate to same type, evaluated to " + ifTrue.type() + " and " + ifFalse.type());

    type = ifTrue.type();

    return this;
}

??

Baizey commented 4 years ago

Ja, tror jeg kom til at implementerer type checking da jeg lavede parsing :p det er svært at efterlade en function med throw new NotImplemented()

Groenbech96 commented 4 years ago

Fint :)