Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typecheck error on atom negation with equivalent type #2399

Merged
merged 4 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/ast/transform/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,12 @@ void TypeCheckerImpl::visit_(type_identity<Atom>, const Atom& atom) {
// Declared attribute and deduced type agree if:
// They are the same type, or
// They are derived from the same constant type.
// They are equivalent types.
bool validAttribute = all_of(argTypes, [&](const analysis::Type& type) {
return type == attributeType || any_of(typeEnv.getConstantTypes(), [&](auto& constantType) {
return isSubtypeOf(attributeType, constantType) && isSubtypeOf(type, constantType);
});
return type == attributeType || areEquivalentTypes(type, attributeType) ||
any_of(typeEnv.getConstantTypes(), [&](auto& constantType) {
return isSubtypeOf(attributeType, constantType) && isSubtypeOf(type, constantType);
});
});

if (!validAttribute) {
Expand Down
1 change: 1 addition & 0 deletions tests/syntactic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ positive_test(dot_identifiers)
positive_test(input_adt_names1)
positive_test(input_adt_names2)
positive_test(input_directive_rfc4180)
positive_test(equivalent_types_in_negation)
if (NOT MSVC)
# does not pass with Visual Studio pre-processor because it preserves all whitespaces
positive_test(whitespaces)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.type List = [name: symbol, rest: List]
.decl list_decl(l:List)
list_decl(["A", ["B", ["C", nil]]]).
list_decl(["D", ["E", ["F", nil]]]).

.type Alias = List

.decl flatten_list(l:List)
flatten_list(l) :- list_decl(l).
flatten_list(l) :- flatten_list([_, l]).

.decl alias_map(a: Alias, l:List)
alias_map(l, l) :-
flatten_list(l).

.decl alias(a: Alias)
alias(a) :- alias_map(a, _).

.decl parent(a: Alias, p: Alias)
parent(a, p) :-
alias_map(a, [_, parent]),
alias_map(p, parent).

.decl has_no_parent(a: Alias)
has_no_parent(a) :-
alias(a), !parent(a, _). // No more error here