lpython icon indicating copy to clipboard operation
lpython copied to clipboard

[Bug] Confusing Type Inference

Open Vipul-Cariappa opened this issue 1 year ago • 1 comments

Type inference fails while converting between types and assigning. Example

>>> x: i32 = i32("123")
semantic error: Type mismatch in annotation-assignment, the types must be compatible
 --> input:1:1
  |
1 | x: i32 = i32("123")
  | ^            ^^^^^ type mismatch ('i32' and 'str')


Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.

But it works while printing.

❯ lp
>>> print(i32("123"))
123

Can i32 function type cast?

If someone can suggest a more meaningful title for this issue, I would appreciate it.

Vipul-Cariappa avatar May 15 '24 13:05 Vipul-Cariappa

I think this might be a duplicated of https://github.com/lcompilers/lpython/issues/2554.

Also discussed at https://lfortran.zulipchat.com/#narrow/stream/311866-LPython/topic/Int.20to.20string.20conversion.

certik avatar May 15 '24 14:05 certik