private void WaddleReturnStmt(ReturnStmtSyntax returnStmt) { if (_currentFunction == null) { throw new SemanticErrorException($"can not use return statement outside of function."); } if (_currentFunction.Type == null) { //Ignore Type if function is typeless return; } // check IsAssignableFrom (function.type, expr.type) var exprType = WaddleExpression(returnStmt.Expression); if (IsAssignableFrom(_currentFunction.Type !, exprType) == false) { throw new SemanticErrorException( $"Function result is of type {_currentFunction.Type!}, the type {exprType} can not be assigned as result."); } }
public bool EnterReturnStmt(ReturnStmtSyntax returnStmt, WaddleContext ctx) { if (_currentFunction == null) { throw new SemanticErrorException($"can not use return statement outside of function."); } if (_currentFunction.Type == null) { //Ignore Type if function is typeless return(true); } // check IsAssignableFrom (function.type, expr.type) var exprType = returnStmt.Expression.Accept(TypeVisitor); if (_currentFunction.Type != exprType) { throw new SemanticErrorException( $"Function result is of type {_currentFunction.Type!}, the type {exprType} can not be assigned as result."); } return(true); }
public virtual TResult Visit(ReturnStmtSyntax syntax) { return(DefaultResult); }
public void LeaveReturnStmt(ReturnStmtSyntax returnStmt, WaddleContext ctx) { }