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

fixed reporting on undefined list attributes #657

Merged
merged 3 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/inmanta/ast/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from inmanta.execute.util import Unknown
from typing import List


try:
from typing import TYPE_CHECKING
except ImportError:
Expand All @@ -49,6 +48,7 @@ def __init__(self, entity: "Entity", value_type: "Type", name: str, multi: bool=
self.__type = value_type
self.__multi = multi
self.__nullallble = nullable
self.low = 0 if nullable else 1
self.comment = None # type: str

def get_type(self) -> "Type":
Expand Down
4 changes: 3 additions & 1 deletion src/inmanta/execute/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,9 @@ def final(self, excns):
attr = self.type.get_attribute(k)
if attr.is_multi():
low = attr.low
length = len(v.value)
# none for list attributes
# list for n-ary relations
length = 0 if v.value is None else len(v.value)
excns.append(UnsetException(
"The object %s is not complete: attribute %s (%s) requires %d values but only %d are set" %
(self, k, attr.location, low, length), self, attr))
Expand Down
15 changes: 15 additions & 0 deletions tests/test_compiler_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ def test_610_multi_add(snippetcompiler):
" attribute b ({dir}/main.cf:11:11) requires 2 values but only 1 are set")


def test_653_list_attribute_unset(snippetcompiler):
snippetcompiler.setup_for_error(
"""
entity Test:
string[] bla
end

Test()

implement Test using std::none
""",
"The object __config__::Test (instantiated at {dir}/main.cf:6) is not complete:"
" attribute bla ({dir}/main.cf:3) requires 1 values but only 0 are set")


def test_670_assign_on_relation(snippetcompiler):
snippetcompiler.setup_for_error_re(
"""
Expand Down