Skip to content

Reading a field off a user operator's result with a scalar operand, (a - 2.0).x, is an internal compiler error #2443

Closed

Description

@joshhickson
type V { x: f64 }

impl V:
    fn sub(self: &Self, rhs: f64) -> V:
        V { x: self.x - rhs }

fn main:
    let a = V { x: 10.0 }
    let t = (a - 2.0).x
    print(f"{t}")
error: internal compiler error: invalid MIR before codegen (a bug in the With compiler, not in this program): place _6.f465 projects component 465 of a scalar (ty=14) in `main`

with analyze g51.w audit:resolution names the expression:

violation: resolution: main at g51.w:9:13 node 10856: field base is ty 14 in MIR, ty 222 after Sema's autoderef (field `x`, MIR f64, Sema f64)

So MIR gives a - 2.0 the scalar operand's type (f64) where Sema has V. Each of these works:
let r = a - 2.0 then r.x; (a - 2.0).get_x() (a method instead of a field); (a - b).x when sub
takes V. Only a field read directly on an operator-method result whose operands have different types
fails.

It came up with std.math's planned Array, where (a * 2.0).shape style chains are routine.

Checked on Linux x86_64 (WSL2) with release builds of main 14a720bd, d0daedbc (which includes #2396) and e38e86f0.

Activity

  1. ehartford commented on Oct 23, 2026

    @ehartford
    Contributor

    Fixed on main (b050a01, PR #2587, stack #2588): one commit with the fixture test/behavior/behav_2443_operator_method_result_field.w, which failed before the fix and passes after; battery GREEN on the stack top 077d684 (669 s, pinned seed nightly-20261023-local-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