Skip to content
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

[BUG] Unexpected compiler failure with conversions between Scalar[DType]. #3801

Open
Drunte opened this issue Nov 23, 2024 · 0 comments
Open
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@Drunte
Copy link

Drunte commented Nov 23, 2024

Bug description

When using a parameter DType in a function, the compiler sometimes fails to convert from Float64 to Scalar[DType]. See the code snippets below.

Steps to reproduce

  • Include relevant code snippet or link to code that did not work as expected.
    snippet1:
fn f[type: DType](i: Int) -> None:
   constrained[type.is_floating_point(), "type failed to be a floating point type"]();
   var val: Scalar[type] = 1.0 / i; #fails to compile here
   #...

Whereas the following two snippets both work.

fn f[type: DType](i: Int) -> None:
   constrained[type.is_floating_point(), "type failed to be a floating point type"]();
   var val: Scalar[type] = 1.0;
   val /= i;
   #...
fn f[type: DType](i: Int) -> None:
   constrained[type.is_floating_point(), "type failed to be a floating point type"]();
   var val: Scalar[type] = rebind[Scalar[type]](1.0 / i);
   #...

The failure in snippet 1 is unexpected since the expression evaluates to Float64 which should be convertible to Scalar[DType], without the need for rebind. The failure is observed in both the stand alone compiler and the playground.

System information

- What OS did you do install Mojo on ? ubuntu 22.04 LTS
- Provide version information for Mojo by pasting the output of `mojo -v` mojo 24.5.0 (e8aacb95)
- Provide Magic CLI version by pasting the output of `magic -V` or `magic --version` magic 0.4.0 - (based on pixi 0.33.0)
@Drunte Drunte added bug Something isn't working mojo-repo Tag all issues with this label labels Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

1 participant