Skip to content

Logging of newtyped uints is broken #3506

Closed

Description

@nikomatsakis

Running this program:

enum Foo = uint;

fn main() {
    let x = Foo(1);
    let y = 1;
    io::println(fmt!("%?, %?", x, y));
}

yields the output:

, 1

Not so good.

Activity

  1. nikomatsakis commented on Sep 15, 2012

    @nikomatsakis
    ContributorAuthor

    This is a real hindrance to debugging the type checker, so I put it as a blocker for 0.4.

  2. Blei commented on Sep 16, 2012

    @Blei
    Contributor

    Even more interesting:

    enum Foo = uint;
    
    fn main() {
        let x = Foo(0);
        let y = Foo(1);
        io::println(fmt!("%?, %?", x, y));
    }
    

    Produces:

    Foo(8892280), 
    

    Where the printed value changes in each invocation...

  3. Blei commented on Sep 16, 2012

    @Blei
    Contributor

    This issue can be fixed with

    diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs
    index a0d6b01..610cc6f 100644
    --- a/src/libcore/repr.rs
    +++ b/src/libcore/repr.rs
    @@ -881,13 +881,13 @@ impl ReprPrinterWrapper : TyVisitor {
                 let mut enum_state = stack.last();
                 match enum_state.state {
                     PreVariant => {
    -                    let disr_ptr = self.printer.ptr as *int;
    -                    if *disr_ptr == disr_val {
    +                    //let disr_ptr = self.printer.ptr as *int;
    +                    //if *disr_ptr == disr_val {
                             enum_state.state = InVariant;
                             self.printer.writer.write_str(name);
    -                        self.printer.bump(sys::size_of::<int>());
    +                        //self.printer.bump(sys::size_of::<int>());
                             stack.set_elt(stack.len() - 1, enum_state);
    -                    }
    +                    //}
                     }
                     InVariant | PostVariant => {}
                 }

    This is almost certainly not the correct fix, but might be a hint about where the problem is.

  4. nikomatsakis commented on Sep 17, 2012

    @nikomatsakis
    ContributorAuthor

    Thanks, I hadn't gotten around to opening repr.rs, but after your
    comments the fix seems pretty obvious. Will push a patch soon.

  5. nikomatsakis commented on Sep 17, 2012

    @nikomatsakis
    ContributorAuthor

    Oh, I should rebase before I repeat @pcwalton's work :)

  6. added a commit that references this issue on May 15, 2021
  7. added a commit that references this issue on Apr 25, 2024
  8. added a commit that references this issue on Aug 21, 2026
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

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions