@Override
 public TypeResult<StatementTypeCheckResult> typeCheck(
     ReturnNode returnStatement, Option<Type> returnType) {
   TypeResultBuilder<StatementTypeCheckResult> typeResult =
       typeResultBuilder(StatementTypeCheckResult.alwaysReturns());
   ExpressionNode expression = returnStatement.getExpression();
   TypeResult<Type> expressionTypeResult = typeInferer.inferType(expression);
   typeResult.addErrors(expressionTypeResult);
   if (!returnType.hasValue()) {
     typeResult.addError(error(returnStatement, new CannotReturnHereError()));
   } else if (expressionTypeResult.hasValue()
       && !subTyping.isSubType(expressionTypeResult.getOrThrow(), returnType.get())) {
     typeResult.addError(
         error(
             expression,
             new WrongReturnTypeError(returnType.get(), expressionTypeResult.getOrThrow())));
   }
   return typeResult.build();
 }
 private TypeResult<StatementTypeCheckResult> typeCheck(
     FunctionSignatureDeclarationNode declaration) {
   return typeChecker().typeCheck(declaration, Option.<Type>none());
 }
示例#3
0
 public static ValueInfo assignableValue(Type type) {
   return new ValueInfo(type, Status.ASSIGNABLE, Option.<ShedValue>none());
 }