[BUG] Compiler doesn't correctly handle the `ref` convention with an `AddressSpace` parameter
Open
Nobody has claimed this yet.
auto_priority_triaged
bug
mojo
- Dominant language
- Mojo
- Stars
- 29.8k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Bug description
As title. CC @lattner.
Steps to reproduce
The error message also got cut off.
from memory import UnsafePointer
struct S:
fn unsafe_ptr(ref self) -> UnsafePointer[Int]:
return {}
fn f[a: AddressSpace](ref[_, a] s: S):
s.unsafe_ptr() # error: invalid call to 'unsafe_ptr':
System information
Mojo 25.4.0.dev2025060220 (d9421ccb)
The error message:
gh_4739.mojo:8:15: error: invalid call to 'unsafe_ptr':
s.unsafe_ptr() # error: invalid call to 'unsafe_ptr':
~~~~~~~~~~~~^~
gh_4739.mojo:4:6: note: function declared here
fn unsafe_ptr(ref self) -> UnsafePointer[Int]:
^
mojo: error: failed to parse the provided Mojo source module
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 by running the provided Mojo reproduction with the listed Mojo version and inspect how the compiler resolves ref[_, a] s when calling unsafe_ptr. Compare the resulting diagnostic with the expected handling of the AddressSpace parameter and ensure the error is complete and accurate.
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
- Mostly clear
- Newbie friendliness
- 35/100