modular / modular/modular

[BUG] Compiler doesn't correctly handle the `ref` convention with an `AddressSpace` parameter

Open
#4,739 6 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.