Skip to content

null as a method-call argument gets no pointer type context: 's.m(null)' / 'S.k(null)' → 'null requires pointer type context' #1496

Closed

Description

@ehartford

Spec: §15 / §16.3c: null takes its pointer type from context; a method parameter is as much a context as a free function's.

Repro (installed v0.15.2.1, stage1 at ba2d5d1):

type S { n: i32 }
impl S:
    fn m(p: *mut i8) -> i32: self.n
fn S.k(p: *mut i8) -> i32: 1
fn main:
    let s = S { n: 3 }
    let a = s.m(null)
    let b = S.k(null)
    print(f"{a} {b}")

Expected: 3 1.
Actual:

error: null requires pointer type context
 --> nul3.w:7:17
7 |     let a = s.m(null)
error: null requires pointer type context
 --> nul3.w:8:17
8 |     let b = S.k(null)

A free function fn f(p: *mut i8) called as f(null) works, so the method-call argument path (instance and static Type.fn) does not hand the parameter type to null as its expected type.

Impact: every facade-rendered method or constructor with a pointer parameter the caller wants to leave NULL — db.sqlite3_exec(sql, null, null, null), Statement.sqlite3_prepare_v2(db, sql, -1, null) (the pzTail out pointer) — needs a typed local (let tail: *mut *const i8 = null) to pass NULL.

Workaround used: modeled-C stage 6's sqlite3 scratch check binds typed null locals. Remove when fixed.

Found while implementing modeled-C stage 6; not fixed there.

Activity

  1. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Verified fixed on main 55739d4 (release binary): s.m(null) and S.k(null) accepted, prints 3 1.

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