Skip to content

Arbitrary functions shouldn't be isomorphic to tuple structs #10200

Closed
@pythonesque

Description

@pythonesque

Currently, if we define a tuple struct:

struct S(t1, ..., tn)

then S has the same type as

fn( x1 : t1, ..., xn : tn) -> S

This allows us to write code that seems unintuitive / wrong:

struct Foo(bool);
let x = Foo(true);
fn foo(_: uint) -> Foo { Foo(false) } // Note that we don't even check to make sure the argument types match in patterns

match x {
    foo(x) => println!("{}", x)
}
// Produces `true`

It seems to me that we should disallow this. My preference would be to just make tuple structs unique, named type constructors that wrap tuple type constructors (not functions). So the type of S above might be (internally) Unique(Tuple(t1, ..., tn), S).

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions