catala/tests/backends/python_name_clash.catala_en
2024-07-04 15:08:13 +02:00

162 lines
4.4 KiB
Plaintext

This test exposes a name clash between the scope function (`ScopeName,`
rewritten to `scope_name`) and the scope variable `scope_name`.
```catala
declaration scope SomeNâme:
input i content integer
output o content integer
scope SomeNâme:
definition o equals i + 1
declaration scope B:
output some_nâme scope SomeNâme
scope B:
definition some_nâme.i equals 1
```
```catala-test-inline
$ catala python
# This file has been generated by the Catala compiler, do not edit!
from catala.runtime import *
from typing import Any, List, Callable, Tuple
from enum import Enum
class SomeName:
def __init__(self, o: Integer) -> None:
self.o = o
def __eq__(self, other: object) -> bool:
if isinstance(other, SomeName):
return (self.o == other.o)
else:
return False
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "SomeName(o={})".format(self.o)
class B:
def __init__(self, some_name: SomeName) -> None:
self.some_name = some_name
def __eq__(self, other: object) -> bool:
if isinstance(other, B):
return (self.some_name == other.some_name)
else:
return False
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "B(some_name={})".format(self.some_name)
class SomeNameIn:
def __init__(self, i_in: Integer) -> None:
self.i_in = i_in
def __eq__(self, other: object) -> bool:
if isinstance(other, SomeNameIn):
return (self.i_in == other.i_in)
else:
return False
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "SomeNameIn(i_in={})".format(self.i_in)
class BIn:
def __init__(self, ) -> None:
pass
def __eq__(self, other: object) -> bool:
if isinstance(other, BIn):
return (True)
else:
return False
def __ne__(self, other: object) -> bool:
return not (self == other)
def __str__(self) -> str:
return "BIn()".format()
def some_name(some_name_in:SomeNameIn):
i = some_name_in.i_in
perhaps_none_arg = handle_exceptions([])
if perhaps_none_arg is None:
if True:
temp_o = (i + integer_of_string("1"))
else:
temp_o = None
else:
x = perhaps_none_arg
temp_o = x
perhaps_none_arg_1 = handle_exceptions([temp_o])
if perhaps_none_arg_1 is None:
if False:
temp_o_1 = None
else:
temp_o_1 = None
else:
x_1 = perhaps_none_arg_1
temp_o_1 = x_1
perhaps_none_arg_2 = temp_o_1
if perhaps_none_arg_2 is None:
raise NoValue(SourcePosition(
filename="tests/backends/python_name_clash.catala_en",
start_line=7, start_column=10,
end_line=7, end_column=11, law_headings=[]))
else:
arg = perhaps_none_arg_2
temp_o_2 = arg
o = temp_o_2
return SomeName(o = o)
def b(b_in:BIn):
perhaps_none_arg_3 = handle_exceptions([])
if perhaps_none_arg_3 is None:
if True:
temp_result = integer_of_string("1")
else:
temp_result = None
else:
x_2 = perhaps_none_arg_3
temp_result = x_2
perhaps_none_arg_4 = handle_exceptions([temp_result])
if perhaps_none_arg_4 is None:
if False:
temp_result_1 = None
else:
temp_result_1 = None
else:
x_3 = perhaps_none_arg_4
temp_result_1 = x_3
perhaps_none_arg_5 = temp_result_1
if perhaps_none_arg_5 is None:
raise NoValue(SourcePosition(
filename="tests/backends/python_name_clash.catala_en",
start_line=16, start_column=14,
end_line=16, end_column=25, law_headings=[]))
else:
arg_1 = perhaps_none_arg_5
temp_result_2 = arg_1
result = some_name(SomeNameIn(i_in = temp_result_2))
result_1 = SomeName(o = result.o)
if True:
temp_some_name = result_1
else:
temp_some_name = result_1
some_name_1 = temp_some_name
return B(some_name = some_name_1)
```
The above should *not* show `some_name = temp_some_name`, but instead `some_name_1 = ...`