use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class LocationTypeTests method assertLocationTypeErrorOnly.
private void assertLocationTypeErrorOnly(String code) {
Model m = assertParse(code);
LocationTypeExtension te = new LocationTypeExtension(m);
m.registerTypeSystemExtension(te);
SemanticConditionList e = m.typeCheck();
assertFalse("No type error occurred", !e.containsErrors());
assertInferFails(code);
}
use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class LocationTypeTests method testInferenceRetypeChecking.
@Test
public void testInferenceRetypeChecking() {
String code = "interface I { Unit m(); } { [Far] I i; I j; i = j; j.m(); }";
Model m = assertParse(code);
LocationTypeExtension te = new LocationTypeExtension(m);
m.registerTypeSystemExtension(te);
SemanticConditionList e = m.typeCheck();
m.typeCheck(new SemanticConditionList());
}
use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class LocationTypeTests method assertTypeOkOnly.
private void assertTypeOkOnly(String code) {
Model m = assertParse(code);
LocationTypeExtension te = new LocationTypeExtension(m);
m.registerTypeSystemExtension(te);
m.getErrors();
SemanticConditionList e = m.typeCheck();
assertTrue(!e.containsErrors() ? "" : "Found error " + e.getFirstError().getMessage(), !e.containsErrors());
assertInferOk(code);
}
use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class ABSTest method assertParse.
protected static Model assertParse(String s, Config... config) {
String preamble = "module UnitTest; export *; ";
preamble = preamble + " import * from ABS.StdLib;";
if (!isSet(WITHOUT_MODULE_NAME, config))
s = preamble + s;
try {
Model p = parseString(s);
if (isSet(WITHOUT_DESUGARING_AFTER_TYPECHECK, config)) {
p.doAACrewrite = false;
p.doForEachRewrite = false;
}
if (isSet(EXPECT_PARSE_ERROR, config)) {
if (!p.hasParserErrors())
fail("Expected to find parse error");
} else {
if (p.hasParserErrors()) {
fail("Failed to parse: " + s + "\n" + p.getParserErrors().get(0).getMessage());
} else {
// make ProductDecl.getProduct() not return null
p.evaluateAllProductDeclarations();
if (isSet(TYPE_CHECK, config)) {
// copy other choice parts of Main.analyzeFlattenAndRewriteModel
p.flattenTraitOnly();
p.collapseTraitModifiers();
p.expandPartialFunctions();
p.expandForeachLoops();
p.expandAwaitAsyncCalls();
if (isSet(WITH_LOC_INF, config)) {
LocationTypeExtension lte = new LocationTypeExtension(p);
p.registerTypeSystemExtension(lte);
}
SemanticConditionList l = p.typeCheck();
if (isSet(EXPECT_TYPE_ERROR, config)) {
if (!l.containsErrors()) {
fail("Expected type errors, but none appeared");
}
} else {
if (l.containsErrors()) {
fail("Failed to typecheck: " + s + "\n" + l.getFirstError().getMessage());
}
}
}
}
}
return p;
} catch (Exception t) {
// TODO: remove
throw new RuntimeException(t);
}
}
use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class FrontendTest method assertTypeErrors.
/**
* Check for and return the first error occurring in 'absCode', or
* null if none found. Produces a test failure if 'config'
* contains EXPECT_TYPE_ERROR but no error found. Produces a test
* failure if 'config' contains EXPECT_WARNING but no warning
* found.
* @param absCode - the test case source code
* @param config - flags
* @return The first error or null
*/
protected SemanticCondition assertTypeErrors(String absCode, Config... config) {
Model m = assertParse(absCode, config);
String msg = "";
SemanticConditionList l = m.typeCheck();
if (l.containsErrors()) {
msg = l.getFirstError().getMsgWithHint(absCode);
} else if (l.containsWarnings() && isSet(EXPECT_WARNING, config)) {
msg = l.getFirstWarning().getMsgWithHint(absCode);
}
assertEquals(msg, isSet(EXPECT_TYPE_ERROR, config), l.containsErrors());
if (isSet(EXPECT_WARNING, config)) {
assertEquals(msg, isSet(EXPECT_WARNING, config), l.containsWarnings());
}
return l.containsErrors() ? l.getFirstError() : null;
}
Aggregations