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 issue with Haskell & Java #496

Merged
merged 1 commit into from
Jan 31, 2024
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 tested/languages/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


class TypeDeclarationMetadata(TypedDict):
names: dict[AllTypes, str | bool]
names: dict[AllTypes, str | tuple[bool, str]]
inner_names: NotRequired[dict[AllTypes, str]]
nested: NotRequired[tuple[str, str]]
nested_overrides: NotRequired[dict[AllTypes, tuple[str, str]]]
Expand Down
8 changes: 6 additions & 2 deletions tested/languages/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@

def _convert_single_type(
language: Language, type_: AllTypes | VariableType, inner: bool
) -> str | bool:
) -> str | tuple[bool, str]:
if isinstance(type_, VariableType):
return type_.data
meta = language.get_declaration_metadata()
Expand All @@ -307,6 +307,8 @@
) -> str:
if not isinstance(declaration, tuple):
simple_result = _convert_single_type(language, declaration, inner)
if isinstance(simple_result, tuple):
simple_result = simple_result[1]

Check warning on line 311 in tested/languages/generation.py

View check run for this annotation

Codecov / codecov/patch

tested/languages/generation.py#L311

Added line #L311 was not covered by tests
assert isinstance(
simple_result, str
), f"{declaration} is a simple type and should generate a string"
Expand All @@ -315,6 +317,8 @@
meta = language.get_declaration_metadata()
base_type, nested = declaration
base = _convert_single_type(language, base_type, inner)
if isinstance(base, tuple):
base = base[0]

start, finish = meta.get("nested", ("[", "]"))

Expand All @@ -335,7 +339,7 @@
# This is a type with "inner" types, i.e. no name, such as Tuple[bool]
return f"{start}{', '.join(converted_nested)}{finish}"
elif base is False:
# This is a type with "rigt" types, i.e. no name, such as bool[]
# This is a type with "right" types, i.e. no name, such as bool[]
return f"{', '.join(converted_nested)}{start}{finish}"
else:
return f"{base}{start}{', '.join(converted_nested)}{finish}"
8 changes: 4 additions & 4 deletions tested/languages/haskell/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def generate_encoder(self, values: list[Value]) -> str:

def get_declaration_metadata(self) -> TypeDeclarationMetadata:
return {
"names": { # type: ignore
"names": {
"integer": "Int",
"real": "Double",
"char": "Char",
Expand All @@ -204,9 +204,9 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"single_precision": "Float",
"double_precision": "Double",
"any": "Object",
"list": True,
"tuple": True,
"sequence": True,
"list": (True, "Data.List"),
"tuple": (True, "Data.Tuple"),
"sequence": (True, "Data.List"),
},
"nested_overrides": {"tuple": ("(", ")")}, # type: ignore
"exception": "Exception",
Expand Down
2 changes: 1 addition & 1 deletion tested/languages/java/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def get_declaration_metadata(self) -> TypeDeclarationMetadata:
"fixed_precision": "BigDecimal",
"list": "List",
"any": "Object",
"array": False,
"array": (False, "array"),
},
"inner_names": {
"boolean": "Boolean",
Expand Down
Loading