[BUG] Lowering issue when implicitly casting references to immutable
Open
Nobody has claimed this yet.
bug
modular-repo
mojo
param-infer-bug
- Dominant language
- Mojo
- Stars
- 29.8k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Bug description
using UnsafePointer(to=data).origin_cast[mut=False]() works fine
from testing import assert_equal
fn main() raises:
var data: Int = 1
var ptr1 = UnsafePointer[mut=False](to=data)
var ptr2 = UnsafePointer[mut=False](to=data)
assert_equal(ptr1, ptr2)
note: call expansion failed
assert_equal(ptr1, ptr2)
^
open-source/max/mojo/stdlib/stdlib/testing/testing.mojo:103:4: note: function instantiation failed
open-source/max/mojo/stdlib/stdlib/testing/testing.mojo:127:12: note: could not simplify operator get_alignof(?, #kgen.target<triple = "x86_64-unknown-linux-gnu", arch = "skylake", features = "+adx,+aes,+avx,+avx2,+bmi,+bmi2,+clflushopt,+cmov,+crc32,+cx16,+cx8,+f16c,+fma,+fsgsbase,+fxsr,+invpcid,+lzcnt,+mmx,+movbe,+pclmul,+popcnt,+prfchw,+rdrnd,+rdseed,+sahf,+sgx,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsavec,+xsaveopt,+xsaves", data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", relocation_model = "pic", simd_bit_width = 256, index_bit_width = 64, accelerator_arch = "nvidia:61">)
Steps to reproduce
...
System information
Mojo 25.6.0.dev2025073105
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction using UnsafePointer[mut=False] and assert_equal, then inspect open-source/max/mojo/stdlib/stdlib/testing/testing.mojo at the reported lines 103 and 127. Trace the failed get_alignof simplification for immutable references; done means the example compiles and the equality assertion succeeds without the lowering diagnostic.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100