Skip to content

Default value for polymorphic parameter fails with confusing error #6313

@prescientmoon

Description

@prescientmoon

Context

  Odin:    dev-2026-02
	OS:      NixOS 25.11 (Xantusia), Linux 6.12.60
	CPU:     AMD Ryzen 7 8840HS w/ Radeon 780M Graphics     
	RAM:     15232 MiB
	Backend: LLVM 18.1.8

Expected Behavior

The following code should compile:

package test
foo :: proc($T: typeid, v: T = {}) {}
bar :: proc() {foo(string)}

Current Behavior

The code fails to compile:

Error: Cannot assign value '{}' of type 'typeid' to 'string' in a procedure argument 
    foo :: proc($T: typeid, v: T = {}) {} 

The following snippet fails with a similar error:

package test
foo :: proc($T: typeid, v: T) {}
bar :: proc() {foo(string, {})}

Annotating {} does make this last snippet pass:

package test
foo :: proc($T: typeid, v: T) {}
bar :: proc() {foo(string, string{})}

This does not work in the previous scenario:

package test
foo :: proc($T: typeid, v: T = T{}) {}
bar :: proc() {foo(string)}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions