Skip to content

Disable implicit casting by default and implement intrinsic functions for casting #1194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

akshanshbhatt
Copy link
Collaborator

@akshanshbhatt akshanshbhatt commented Oct 12, 2022

Todo:

As of now, the example in #1142 gives the output as we expected -

bat examples/expr2.py
───────┬─────────────────────────────────────────────────────────────
       │ File: examples/expr2.py
───────┼─────────────────────────────────────────────────────────────
   1 +from ltypes import i32
   2 +3def main0():
   4x: i32
   5 ~x = 1/2
   6print(x)
   78 ~main0()
───────┴─────────────────────────────────────────────────────────────
❯ lpy --show-asr examples/expr2.py
semantic error: Type mismatch in assignment, the types must be compatible
 --> examples/expr2.py:5:5
  |
5 |     x = 1/2
  |     ^   ^^^ type mismatch ('i32' and 'f64')


Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that needs to be fixed).

@akshanshbhatt akshanshbhatt changed the title Disable implicit type casting by default and implement intrinsic functions for casting Disable implicit casting by default and implement intrinsic functions for casting Oct 12, 2022
@certik
Copy link
Contributor

certik commented Oct 13, 2022

Thanks for working on this! This was on my TODO list, I think we want to do this change soon, since it's a breaking change.

@certik
Copy link
Contributor

certik commented Oct 13, 2022

We don't need to add the compiler flag in this PR. If there is a need, we can add it later.

@akshanshbhatt
Copy link
Collaborator Author

@certik, The functions are mainly working fine. I have to work on the BinOp casting (for example - making i32(3.2 + 1.5) work) and a few other things before I can complete this PR. However, there are a few things where I need some help -

$ cat examples/expr2.py
from ltypes import i32

def main0():
    x: f64
    x = i32(6.8)
    print(x)

main0()
$ lpython examples/expr2.py
semantic error: Type mismatch in assignment, the types must be compatible
 --> examples/expr2.py:5:5
  |
5 |     x = i32(6.8)
  |     ^       ^^^ type mismatch ('f64' and 'i32')


Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that needs to be fixed).

Here the error message should point to the complete i32() part but it instead, it just points to the argument passed. Ideally, it should be -

  |
5 |     x = i32(6.8)
  |     ^   ^^^^^^^^ type mismatch ('f64' and 'i32')

How can I fix this?

@certik
Copy link
Contributor

certik commented Oct 14, 2022

You have to pass in the location information of the i32 node, not the argument 6.8.

@czgdp1807
Copy link
Collaborator

Any progress on this? I think we need to this early especially for the following cases,

  1. Casting while passing function arguments.
  2. Casting while passing initial values to constructors.

@akshanshbhatt If you don't have time then let me know I can finish this as I anyways need this to happen. Thanks.

@czgdp1807 czgdp1807 self-assigned this Nov 2, 2022
@czgdp1807
Copy link
Collaborator

Self-assigning. I will complete this tomorrow. Thanks.

@czgdp1807
Copy link
Collaborator

Closing in favour of #1271

@czgdp1807 czgdp1807 closed this Nov 5, 2022
@akshanshbhatt
Copy link
Collaborator Author

Closing in favour of #1271

Thanks for working on this, @czgdp1807! I just saw your previous messages on this PR; sorry for that - I was busy with my midsemester exams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants