Skip to content

A default argument resolves in the caller scope: a program that declares its own src() captures panic(loc: &str = src()) and the checker reports a bogus argument error inside embedded std #2568

Closed

Description

@ehartford

Repro

use std.builtins.print_bool
extern fn src() -> i32
fn main: print_bool(true)
error: wrong argument type in call to 'panic'
 --> <embedded-std>/std/string.w:103:32
  = label @103:32 argument expression 'src()' has type i32   (the user's src)
  = note: parameter 'loc' expects &str

A plain fn src() -> *mut i32: null instead gives symbol 'src' is not visible from this module at std/builtins.w:97 (the default argument of panic). Renaming the function (srcx) passes.

Cause (hypothesis, from the sites)

lib/std/builtins.w:97: pub fn panic(msg: &str, loc: &str = src()) -> Never. The default argument's expression is re-resolved at each call site in the caller's scope, so a caller module that declares src shadows the builtin (Sema.syms.src). The reported location (string.w:103, a doc-comment line) is the default-argument node's span, not the call's.

Expected

A default argument is evaluated in the callee's declaring scope (hygiene), or src() is an intrinsic no user name can shadow. Found by a C migrator fixture whose C function was named src (M*LIB Phase 4 work).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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