Skip to content

Logging of newtyped uints is broken #3506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nikomatsakis opened this issue Sep 15, 2012 · 5 comments
Closed

Logging of newtyped uints is broken #3506

nikomatsakis opened this issue Sep 15, 2012 · 5 comments
Labels
A-codegen Area: Code generation
Milestone

Comments

@nikomatsakis
Copy link
Contributor

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.

@nikomatsakis
Copy link
Contributor Author

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

@Blei
Copy link
Contributor

Blei commented Sep 16, 2012

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...

@Blei
Copy link
Contributor

Blei commented Sep 16, 2012

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.

@nikomatsakis
Copy link
Contributor Author

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

@nikomatsakis
Copy link
Contributor Author

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

bors pushed a commit to rust-lang-ci/rust that referenced this issue May 15, 2021
RalfJung pushed a commit to RalfJung/rust that referenced this issue Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

No branches or pull requests

3 participants