Skip to content

Commit

Permalink
Extend base type error message
Browse files Browse the repository at this point in the history
  • Loading branch information
tytus-metrycki authored and XiaowenHu96 committed Jul 31, 2020
1 parent a744446 commit 94e5973
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ast/transform/AstSemanticChecker.cpp
Expand Up @@ -1187,6 +1187,7 @@ void AstSemanticCheckerImpl::checkNamespaces() {
bool AstExecutionPlanChecker::transform(AstTranslationUnit& translationUnit) {
auto* relationSchedule = translationUnit.getAnalysis<RelationSchedule>();
auto* recursiveClauses = translationUnit.getAnalysis<RecursiveClauses>();
auto&& report = translationUnit.getErrorReport();

for (const RelationScheduleStep& step : relationSchedule->schedule()) {
const std::set<const AstRelation*>& scc = step.computed();
Expand All @@ -1212,7 +1213,7 @@ bool AstExecutionPlanChecker::transform(AstTranslationUnit& translationUnit) {
if (version <= maxVersion) {
for (const auto& cur : clause->getExecutionPlan()->getOrders()) {
if (cur.first >= version) {
translationUnit.getErrorReport().addDiagnostic(Diagnostic(Diagnostic::Type::ERROR,
report.addDiagnostic(Diagnostic(Diagnostic::Type::ERROR,
DiagnosticMessage(
"execution plan for version " + std::to_string(cur.first),
cur.second->getSrcLoc()),
Expand Down Expand Up @@ -1258,8 +1259,16 @@ void TypeChecker::visitAtom(const AstAtom& atom) {
return isA<RecordType>(type) && !isA<SubsetType>(type);
});
if (!validAttribute && !Global::config().has("legacy")) {
report.addError("Atoms argument type is not a subtype of its declared type",
arguments[i]->getSrcLoc());
auto primeryDiagnostic =
DiagnosticMessage("Atoms argument type is not a subtype of its declared type",
arguments[i]->getSrcLoc());

auto declaredTypeInfo =
DiagnosticMessage(tfm::format("The argument declared type is %s", typeName),
attributes[i]->getSrcLoc());

report.addDiagnostic(Diagnostic(Diagnostic::Type::ERROR, std::move(primeryDiagnostic),
{std::move(declaredTypeInfo)}));
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/semantic/extended_subtypes3/extended_subtypes3.err
@@ -1,19 +1,37 @@
Error: Atoms argument type is not a subtype of its declared type in file extended_subtypes3.dl at line 20
SymbolChain(a, a, a) :- SymbolChain(a, _, _).
---------------^------------------------------
The argument declared type is symbolB in file extended_subtypes3.dl at line 18
.decl SymbolChain(a: symbolA, b: symbolB, c: symbolC)
---------------------------------^--------------------
Error: Atoms argument type is not a subtype of its declared type in file extended_subtypes3.dl at line 20
SymbolChain(a, a, a) :- SymbolChain(a, _, _).
------------------^---------------------------
The argument declared type is symbolC in file extended_subtypes3.dl at line 18
.decl SymbolChain(a: symbolA, b: symbolB, c: symbolC)
---------------------------------------------^--------
Error: Atoms argument type is not a subtype of its declared type in file extended_subtypes3.dl at line 21
SymbolChain(b, b, b) :- SymbolChain(_, b, _).
------------------^---------------------------
The argument declared type is symbolC in file extended_subtypes3.dl at line 18
.decl SymbolChain(a: symbolA, b: symbolB, c: symbolC)
---------------------------------------------^--------
Error: Atoms argument type is not a subtype of its declared type in file extended_subtypes3.dl at line 33
RecordSubtypes(x, [1, x], x) :- RecordSubtypes(x, _, _). // error in [1, x] and x
--------------------------^-------------------------------------------------------
The argument declared type is S2List in file extended_subtypes3.dl at line 31
.decl RecordSubtypes(a: List, b: S1List, c: S2List)
--------------------------------------------^-------
Error: Atoms argument type is not a subtype of its declared type in file extended_subtypes3.dl at line 34
RecordSubtypes(y, y, y) :- RecordSubtypes(y, _, _). // Should be error in second place and third place.
------------------^-------------------------------------------------------------------------------------
The argument declared type is S1List in file extended_subtypes3.dl at line 31
.decl RecordSubtypes(a: List, b: S1List, c: S2List)
---------------------------------^------------------
Error: Atoms argument type is not a subtype of its declared type in file extended_subtypes3.dl at line 34
RecordSubtypes(y, y, y) :- RecordSubtypes(y, _, _). // Should be error in second place and third place.
---------------------^----------------------------------------------------------------------------------
The argument declared type is S2List in file extended_subtypes3.dl at line 31
.decl RecordSubtypes(a: List, b: S1List, c: S2List)
--------------------------------------------^-------
6 errors generated, evaluation aborted
21 changes: 21 additions & 0 deletions tests/semantic/rule_typecompat/rule_typecompat.err
Expand Up @@ -16,6 +16,9 @@ Warning: No rules/facts defined for relation E in file rule_typecompat.dl at lin
Error: Atoms argument type is not a subtype of its declared type in file rule_typecompat.dl at line 15
A(x) :- B(x).
--^-----------
The argument declared type is T in file rule_typecompat.dl at line 6
.decl A (t:T)
-----------^--
Error: Unable to deduce type for variable x in file rule_typecompat.dl at line 18
A(x) :- F(x,x).
--^-------------
Expand Down Expand Up @@ -43,6 +46,9 @@ A(x) :- G(x,y).
Error: Atoms argument type is not a subtype of its declared type in file rule_typecompat.dl at line 28
G(x,x) :- A(x).
----^-----------
The argument declared type is R in file rule_typecompat.dl at line 12
.decl G (t:T, r:R)
----------------^--
Error: Ungrounded variable y in file rule_typecompat.dl at line 30
G(x,y) :- A(x).
----^-----------
Expand All @@ -67,6 +73,9 @@ A(x) :- A(x), B(y), C(z).
Error: Atoms argument type is not a subtype of its declared type in file rule_typecompat.dl at line 39
F(x,y) :- F(x,z), G(z,y).
----^---------------------
The argument declared type is T in file rule_typecompat.dl at line 11
.decl F (r:R, t:T)
----------------^--
Error: Ungrounded variable y in file rule_typecompat.dl at line 41
F(x,y) :- F(x,z), G(z,x).
----^---------------------
Expand Down Expand Up @@ -115,18 +124,30 @@ F(x,y) :- F(x,v), F(w,y), !H(v), !D(v).
Error: Atoms argument type is not a subtype of its declared type in file rule_typecompat.dl at line 52
F(x,y) :- F(x,v), F(w,y), !H(v), !D(v).
------------------------------------^---
The argument declared type is R in file rule_typecompat.dl at line 9
.decl D (r:R)
-----------^--
Warning: Variable v only occurs once in file rule_typecompat.dl at line 53
F(x,y) :- F(x,v), F(w,y), !H(w), !D(w).
--------------^-------------------------
Error: Atoms argument type is not a subtype of its declared type in file rule_typecompat.dl at line 53
F(x,y) :- F(x,v), F(w,y), !H(w), !D(w).
-----------------------------^----------
The argument declared type is T in file rule_typecompat.dl at line 5
.decl H (t:T)
-----------^--
Error: Atoms argument type is not a subtype of its declared type in file rule_typecompat.dl at line 54
F(x,y) :- F(x,v), F(w,y), !H(w), !D(v).
-----------------------------^----------
The argument declared type is T in file rule_typecompat.dl at line 5
.decl H (t:T)
-----------^--
Error: Atoms argument type is not a subtype of its declared type in file rule_typecompat.dl at line 54
F(x,y) :- F(x,v), F(w,y), !H(w), !D(v).
------------------------------------^---
The argument declared type is R in file rule_typecompat.dl at line 9
.decl D (r:R)
-----------^--
Error: Unable to deduce type for variable x in file rule_typecompat.dl at line 57
F(x,y) :- F(x,y), x > y.
--^-----------------------
Expand Down
3 changes: 3 additions & 0 deletions tests/semantic/type_as2/type_as2.err
@@ -1,6 +1,9 @@
Error: Atoms argument type is not a subtype of its declared type in file type_as2.dl at line 22
B(as(x, symbol)) :- A(x).
--^-----------------------
The argument declared type is symbol1 in file type_as2.dl at line 21
.decl B(x: symbol1)
-----------^--------
Error: Unable to deduce type of the argument (cast) in file type_as2.dl at line 23
B(as(x, float)) :- A(x).
--^----------------------
Expand Down
9 changes: 9 additions & 0 deletions tests/semantic/type_system12/type_system12.err
@@ -1,10 +1,19 @@
Error: Atoms argument type is not a subtype of its declared type in file type_system12.dl at line 38
C(x) :- B(x). // Error
--^-----------------------------------------
The argument declared type is S1 in file type_system12.dl at line 37
.decl C(x : S1)
------------^---
Error: Atoms argument type is not a subtype of its declared type in file type_system12.dl at line 39
C(x) :- !A(x), B(x). // Error
--^-----------------------------------------
The argument declared type is S1 in file type_system12.dl at line 37
.decl C(x : S1)
------------^---
Error: Atoms argument type is not a subtype of its declared type in file type_system12.dl at line 39
C(x) :- !A(x), B(x). // Error
-----------^--------------------------------
The argument declared type is S2 in file type_system12.dl at line 23
.decl A(x : S2)
------------^---
3 errors generated, evaluation aborted
3 changes: 3 additions & 0 deletions tests/semantic/type_system14/type_system14.err
@@ -1,4 +1,7 @@
Error: Atoms argument type is not a subtype of its declared type in file type_system14.dl at line 24
RG(val) :- RD(val), RE(cat("",val)).
---^---------------------------------
The argument declared type is B in file type_system14.dl at line 21
.decl RG(x:B)
-----------^--
1 errors generated, evaluation aborted

0 comments on commit 94e5973

Please sign in to comment.