catala/tests/backends/python_name_clash.catala_en
Louis Gesbert c01d4ac512 Fix exception positions being lost during translation/optimisations
Positions within the Default terms are specially important since they can come
from separate definitions in the source (before this, we would be falling back
to the single declaration).
2024-04-30 17:56:06 +02:00

157 lines
5.1 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
try:
def temp_o(_:Unit):
def temp_o_1(_:Unit):
return True
def temp_o_2(_:Unit):
return (i + integer_of_string("1"))
return handle_default(SourcePosition(filename="tests/backends/python_name_clash.catala_en",
start_line=10, start_column=23,
end_line=10, end_column=28,
law_headings=[]), [], temp_o_1, temp_o_2)
def temp_o_3(_:Unit):
return False
def temp_o_4(_:Unit):
raise Empty
temp_o_5 = handle_default(SourcePosition(filename="tests/backends/python_name_clash.catala_en",
start_line=7, start_column=10,
end_line=7, end_column=11,
law_headings=[]), [temp_o], temp_o_3,
temp_o_4)
except Empty:
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=[]))
o = temp_o_5
return SomeName(o = o)
def b(b_in:BIn):
try:
def temp_result(_:Unit):
def temp_result_1(_:Unit):
return True
def temp_result_2(_:Unit):
return integer_of_string("1")
return handle_default(SourcePosition(filename="tests/backends/python_name_clash.catala_en",
start_line=16, start_column=33,
end_line=16, end_column=34,
law_headings=[]), [], temp_result_1,
temp_result_2)
def temp_result_3(_:Unit):
return False
def temp_result_4(_:Unit):
raise Empty
temp_result_5 = handle_default(SourcePosition(filename="tests/backends/python_name_clash.catala_en",
start_line=16, start_column=14,
end_line=16, end_column=25,
law_headings=[]), [temp_result],
temp_result_3, temp_result_4)
except Empty:
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=[]))
result = some_name(SomeNameIn(i_in = temp_result_5))
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 = ...`