Skip to content

Operator dispatch: T op 1.0 works, but 1.0 op T doesn't #19035

Closed
@japaric

Description

@japaric

STR

Given the proper (commutative) Add/Mul implementations. (See this playpen link)

const I: Complex<f32> = Complex { re: 0., im: 1. };

let z = I * 3.;  // OK
let z = I + 3.;  // OK
let z = 3. * I;  // Err
let z = 3. + I;  // Err

Output

error: mismatched types: expected `_`, found `Complex<f32>` (expected floating-point variable, found struct Complex)

@nikomatsakis Could this work in the future? It would be great if could type 3. + 4. * I instead of I * 4. + 3., the former feels more natural.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions