Skip to content

[BUG] Compiler fails to find correct overload with inferred parameter on a generic struct #4538

@soraros

Description

@soraros

Bug description

As title. Related to #4199. CC @dgurchenkov.

Steps to reproduce

Code:

@value
struct Ptr[dtype: DType = DType.int32]:
  fn store(self, offset: Int, val: Int):
    pass

  fn store[width: Int, //](self, offset: Int):
    pass

fn main():
  p = Ptr()
  i = 1
  p.store[width=4](i)  # error

Error:

/workspaces/ubuntu/max/playground/main.mojo:31:19: error: no matching method in call to 'store'
  p.store[width=4](i)
  ~~~~~~~~~~~~~~~~^~~
/workspaces/ubuntu/max/playground/main.mojo:22:6: note: candidate not viable: missing 1 required positional argument: 'val'
  fn store(self, offset: Int, val: Int):
     ^
/workspaces/ubuntu/max/playground/main.mojo:25:6: note: candidate not viable: inferred parameter passed out of order: 'width'
  fn store[width: Int, //](self, offset: Int):

System information

mojo 25.4.0.dev2025050905 (e3051145)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmodular-repomojoIssues that are related to mojo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions