Skip to content

Commit 29a3f85

Browse files
authored
Allow deftype* forms to declare no fields (#541)
* Allow `deftype*` forms to declare no fields * Changelog
1 parent 8a5d76c commit 29a3f85

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
* Fixed a bug where Basilisp would throw an exception when comparing seqs by `=` to non-seqable values (#530)
1818
* Fixed a bug where aliased Python submodule imports referred to the top-level module rather than the submodule (#533)
1919
* Fixed a bug where static methods and class methods on types created by `deftype` could not be referred to directly (defeating the purpose of the static or class method) (#537)
20+
* Fixed a bug where `defftype` forms could not be declared without at least one field (#540)
2021

2122
## [v0.1.dev13] - 2020-03-16
2223
### Added

src/basilisp/lang/compiler/analyzer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,8 @@ def _deftype_ast( # pylint: disable=too-many-branches
15541554
nelems = count(form)
15551555
if nelems < 3:
15561556
raise AnalyzerException(
1557-
"deftype forms must have 3 or more elements, as in: (deftype* name fields [bases+impls])",
1557+
"deftype forms must have 3 or more elements, as in: "
1558+
"(deftype* name fields :implements [bases+impls])",
15581559
form=form,
15591560
)
15601561

src/basilisp/lang/compiler/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ def _deftype_to_py_ast( # pylint: disable=too-many-branches
13341334
name=type_name,
13351335
bases=bases,
13361336
keywords=[],
1337-
body=type_nodes,
1337+
body=type_nodes or [ast.Pass()],
13381338
decorator_list=[decorator],
13391339
),
13401340
ast.Call(

tests/basilisp/compiler_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,14 @@ def test_deftype_may_not_add_extra_methods_to_interface(self, lcompile: CompileF
605605
"""
606606
)
607607

608+
@pytest.mark.parametrize(
609+
"code", ["(deftype* Shape [])", "(deftype* Shape [] :implements [])"]
610+
)
611+
def test_deftype_interface_may_have_no_fields_or_methods(
612+
self, lcompile: CompileFn, code: str,
613+
):
614+
lcompile(code)
615+
608616
def test_deftype_interface_may_implement_only_some_object_methods(
609617
self, lcompile: CompileFn
610618
):

0 commit comments

Comments
 (0)