modular / modular/modular

[BUG] Functions cannot resolve parameter to default when using parameter on an `Optional` type

Open
#6,542 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

auto_priority_triaged bug bug_feature_triaged mojo origins
Dominant language
Mojo
Stars
29.8k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Bug description
Actual behavior

I get the error "invalid call to 'print_cstr': value passed to 'cstr' cannot be converted from 'None' to 'Optional[CStringSlice[cstr_origin]]', it depends on an unresolved parameter 'cstr_origin._mlir_origin'" when trying the failing examples listed below.

Expected behavior

I'd expect the inclusion of a default parameter value (cstr_origin: ImmutOrigin=ImmutExternalOrigin) to make the first example work. There should be enough information present for the compiler to know that None should cast to Optional[CStringSlice[ImmutExternalOrigin]]. The fact that this doesn't work makes using the new non-nullable versions of CStringSlice and UnsafePointer needlessly verbose.

Steps to reproduce
from std.ffi import CStringSlice

# Doesn't work
def main():
    print_cstr(None)

def print_cstr[cstr_origin: ImmutOrigin=ImmutExternalOrigin](cstr: Optional[CStringSlice[cstr_origin]]):
    if cstr:
        print(cstr.value())
    else:
        print("Null")

# Still doesn't work
def main():
    print_cstr()

def print_cstr[cstr_origin: ImmutOrigin=ImmutExternalOrigin](cstr: Optional[CStringSlice[cstr_origin]]=None):
    if cstr:
        print(cstr.value())
    else:
        print("Null")

# Works but needlessly verbose
def main():
    print_cstr[cstr_origin=ImmutExternalOrigin](None)

def print_cstr[cstr_origin: ImmutOrigin=ImmutExternalOrigin](cstr: Optional[CStringSlice[cstr_origin]]):
    if cstr:
        print(cstr.value())
    else:
        print("Null")
System information
System
------------
       Pixi version: 0.53.0
           Platform: linux-64
   Virtual packages: __unix=0=0
                   : __linux=6.18.7=0
                   : __glibc=2.39=0
                   : __cuda=13.0=0
                   : __archspec=1=zen4
          Cache dir: /home/ryan/.cache/rattler/cache
       Auth storage: /home/ryan/.rattler/credentials.json
   Config locations: No config files found

Global
------------
            Bin dir: /home/ryan/.pixi/bin
    Environment dir: /home/ryan/.pixi/envs
       Manifest dir: /home/ryan/.pixi/manifests/pixi-global.toml

Workspace
------------
               Name: platform-mojo
            Version: 0.1.0
      Manifest file: /home/ryan/Documents/programming/platform-mojo/pixi.toml
       Last updated: 13-05-2026 00:18:55

Environments
------------
        Environment: default
           Features: default
           Channels: conda-forge, https://conda.modular.com/max
   Dependency count: 2
       Dependencies: mojo, libxcb
   Target platforms: linux-64
    Prefix location: /home/ryan/Documents/programming/platform-mojo/.pixi/envs/default

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 failing examples in the issue and compare them with the explicit cstr_origin example that works. Trace parameter-default and Optional generic resolution for CStringSlice, then add or update regression coverage for both None calls. Done means the implicit default resolves the parameter without requiring an explicit generic argument.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.