Skip to content

Commit

Permalink
Merge pull request #496 from dodona-edu/enhance/even-more-tweaks
Browse files Browse the repository at this point in the history
Fix issue with Haskell & Java
  • Loading branch information
niknetniko authored Jan 31, 2024
2 parents f8b7539 + 52ff345 commit 2f31b08
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
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 generate_selector(

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 @@ def generate_type_declaration(
) -> str:
if not isinstance(declaration, tuple):
simple_result = _convert_single_type(language, declaration, inner)
if isinstance(simple_result, tuple):
simple_result = simple_result[1]
assert isinstance(
simple_result, str
), f"{declaration} is a simple type and should generate a string"
Expand All @@ -315,6 +317,8 @@ def generate_type_declaration(
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 @@ def generate_type_declaration(
# 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

0 comments on commit 2f31b08

Please sign in to comment.