use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class LocationTypeExtension method checkAssignable.
@Override
public void checkAssignable(Type adaptTo, AdaptDirection dir, Type rht, Type lht, ASTNode<?> n) {
LocationType lhlt = getLocationType(lht);
LocationType rhlt = getLocationType(rht);
LocationType adaptedRhlt = rhlt;
if (adaptTo != null) {
adaptedRhlt = rhlt.adaptTo(getLocationType(adaptTo), dir);
}
if (!adaptedRhlt.isSubtypeOf(lhlt)) {
errors.add(new TypeError(n, ErrorMessage.LOCATION_TYPE_CANNOT_ASSIGN, adaptedRhlt.toString(), lhlt.toString()));
}
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class ConstraintSolver method resolveAdapt.
/**
* Resolve one adapt constrained
* @param resolved - Already resolved vars and their type
* @param adapt - The constraint to resolve
*/
private void resolveAdapt(Map<LocationTypeVar, LocationType> resolved, Constraint.Adapt adapt) {
LocationTypeVar expected = getRewritten(adapt.expected);
LocationTypeVar actual = getRewritten(adapt.actual);
AdaptDirection dir = adapt.dir;
LocationTypeVar adaptTo = getRewritten(adapt.adaptTo);
ASTNode<?> node = adapt.node;
if (!resolved.containsKey(adaptTo)) {
keep(adapt);
return;
}
if (adaptTo == NEAR) {
add(Constraint.eq(expected, actual, node));
return;
}
if (adaptTo == SOMEWHERE) {
add(Constraint.eq(expected, SOMEWHERE, node));
return;
}
if (adaptTo == FAR) {
LocationTypeVar res;
if (actual == NEAR) {
res = FAR;
} else if (actual == SOMEWHERE) {
res = SOMEWHERE;
} else if (actual == BOTTOM) {
errors.add(new LocationTypeInferException(new TypeError(node, ErrorMessage.LOCATION_TYPE_CALL_ON_BOTTOM, new String[0])));
return;
} else if (actual == FAR) {
res = SOMEWHERE;
} else {
keep(adapt);
return;
}
add(Constraint.eq(expected, res, node));
return;
}
keep(adapt);
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class ConstraintSolver method resolveEq.
/**
* Resolve one eq constrained
* @param resolved - Already resolved vars and their type
* @param eq - The constraint to resolve
*/
private void resolveEq(Map<LocationTypeVar, LocationType> resolved, Constraint.Eq eq) {
LocationTypeVar expected = getRewritten(eq.expected);
LocationTypeVar actual = getRewritten(eq.actual);
ASTNode<?> node = eq.node;
if (expected == actual)
return;
if (expected.isLocationType() && actual.isLocationType()) {
errors.add(new LocationTypeInferException(new TypeError(node, ErrorMessage.LOCATION_TYPE_CANNOT_ASSIGN, expected.toString(), actual.toString())));
return;
}
if (expected.isLocationType()) {
rewrite(actual, expected);
resolved.put(actual, expected.asLocationType());
return;
}
if (actual.isLocationType()) {
rewrite(expected, actual);
resolved.put(expected, actual.asLocationType());
return;
}
rewrite(expected, actual);
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class NullCheckerExtension method checkVarDeclStmt.
@Override
public void checkVarDeclStmt(VarDeclStmt varDeclStmt) {
VarDecl d = varDeclStmt.getVarDecl();
Type t = d.getType();
setAnnotatedType(t, varDeclStmt);
if (!shouldHaveNullableType(t))
return;
NullableType nt = getNullableTypeDefault(t);
if (nt == NullableType.Nonnull && !d.hasInitExp()) {
errors.add(new TypeError(varDeclStmt, ErrorMessage.NULLABLE_TYPE_MISMATCH, NullableType.Null.toString(), nt.toString()));
}
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class DeltaSamplesTest method test_ticket329.
@Test
public void test_ticket329() throws Exception {
Model m = assertParseFileOk("abssamples/deltas/bug329.abs");
SemanticConditionList errs = m.typeCheck();
/* We are expecting a missing delta in product M.PL: */
assertThat(errs.getFirstError(), instanceOf(TypeError.class));
TypeError te = (TypeError) errs.getFirstError();
Assert.assertEquals(ErrorMessage.NAME_NOT_RESOLVABLE, te.msg);
}
Aggregations