Commit ba953f8b authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: semantic check - property getter return value (issue #427)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 9fcd99a8
......@@ -14,6 +14,8 @@ import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.Assignment.Assignment_type;
import org.eclipse.titan.designer.AST.GovernedSimple.CodeSectionType;
import org.eclipse.titan.designer.AST.INamedNode;
import org.eclipse.titan.designer.AST.IType;
import org.eclipse.titan.designer.AST.IType.Type_type;
import org.eclipse.titan.designer.AST.IType.ValueCheckingOptions;
import org.eclipse.titan.designer.AST.IValue;
import org.eclipse.titan.designer.AST.ReferenceFinder;
......@@ -51,7 +53,8 @@ public final class Return_Statement extends Statement {
private static final String INVALIDSETTERRETURN = "Return statement cannot be used in a property setter";
private static final String FULLNAMEPART = ".returnexpression";
private static final String STATEMENT_NAME = "return";
private static final String RETURNTYPEEXPECTED = "Return type `{0}'' expected";
private final TTCN3Template template;
private boolean genRestrictionCheck = false;
......@@ -133,7 +136,16 @@ public final class Return_Statement extends Statement {
final INamedNode node = block.getNameParent();
if (node instanceof Property_Type) {
final Property_Type property = (Property_Type)node;
// TODO check return type if it matches the property type
if (template == null) {
final IType propType = property.getFieldType(timestamp, null, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
location.reportSemanticError(MessageFormat.format(MISSINGTEMPLATE, propType.getTypename()));
} else {
final Type_type templateType = template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (templateType != property.getTypetypeTtcn3()) {
final IType propType = property.getFieldType(timestamp, null, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
location.reportSemanticError(MessageFormat.format(RETURNTYPEEXPECTED, propType.getTypename()));
}
}
return;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment