Incorrect type hints cause segfault.
The following code provides a type hint that indicates that the variable a should be a list of integers while the actual type is int. Then codon gets a segfault. CPython can normally print "1" with this test.
test.py
a = 1 # a: int
a: list[int]
print(a)
The actual output: Segmentation Fault The expected output: 1
Reproduce step:
download the Pre-built binaries for Linux Type " codon run --release test.py" in the console.
Environment: Ubuntu 18.04 Codon v0.16.0 CPython 3.10.8
@xiaxinmeng Type hints were introduced in Python 3.5 to enable type annotations for function arguments and return values. The list[int] syntax specifies that the variable a should be a list of integers.
However, type hints in Python are optional and do not affect the actual behavior of the program. They are primarily used for documentation purposes and to improve code readability.
In Codon, a: list[int] would indeed declare a variable a of type list[int], but it would not necessarily initialize it. Variable initialization would require an assignment statement such as a = [] to create an empty list or a = [1, 2, 3] to create a list with three integers.
@arshajii SIGSEGV: Linux Segmentation Fault | Signal 11 trying to print an uninitialized variable. Maybe a duplicate.
a = 1 # a: int
print(a) # 1
a: list[int]
print(type(a) is list[int]) # True
print(a) # Segmentation fault (core dumped)
@elisbyberi Thanks. I have also conducted a further investigation and included some additional test cases to help address this issue
case 1:
a: list[int]
x, y = a #Segmentation fault
case 2:
a: list[int]
y = a # work normal
case 3
a: list[int]
y = a
print(y) # segmentation fault
This is bug on our side. Thank you for the report.