Skip to content
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

Empty classes dislike being placed into vectors #2509

Closed
brson opened this issue Jun 5, 2012 · 5 comments
Closed

Empty classes dislike being placed into vectors #2509

brson opened this issue Jun 5, 2012 · 5 comments
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Milestone

Comments

@brson
Copy link
Contributor

brson commented Jun 5, 2012

class c {
    new() { }
}

fn main() {
    let a = c();
    let x = [a];
    let y = x[0];
}
rust: upcall fail 'bounds check', /home/banderson/Dev/rust/src/test/run-pass/test.rs:8
rust: domain main @0x66e8e30 root task failed

Also:

class c {
    new() { }
}

fn main() {
    for [c()].each {|i|
    }
}
==19949==
==19949== Process terminating with default action of signal 8 (SIGFPE)
==19949==  Integer divide by zero at address 0x40339A836
==19949==    at 0x401068: vec::unpack_slice7::_79a2ea93cf50478f::_00 (in /home/banderson/Dev/rust/build/x86_64-unknown-linux-gnu/test/run-pass/test.stage1-x86_64-unknown-linux-gnu)
==19949==    by 0x400F0E: vec::each6::_67468c156592b8bf::_00 (in /home/banderson/Dev/rust/build/x86_64-unknown-linux-gnu/test/run-pass/test.stage1-x86_64-unknown-linux-gnu)
==19949==    by 0x400E90: vec::extensions::each5::_4ad0f86fc13c8027::_00 (in /home/banderson/Dev/rust/build/x86_64-unknown-linux-gnu/test/run-pass/test.stage1-x86_64-unknown-linux-gnu)
==19949==    by 0x400C06: main::_f8ae15773a042ac1::_00 (in /home/banderson/Dev/rust/build/x86_64-unknown-linux-gnu/test/run-pass/test.stage1-x86_64-unknown-linux-gnu)
==19949==    by 0x400D1B: _rust_main (in /home/banderson/Dev/rust/build/x86_64-unknown-linux-gnu/test/run-pass/test.stage1-x86_64-unknown-linux-gnu)
==19949==    by 0x5341D1A: task_start_wrapper(spawn_args*) (rust_task.cpp:153)

@ghost ghost assigned catamorphism Jun 5, 2012
@brson
Copy link
Contributor Author

brson commented Jun 5, 2012

This seems to be a problem with empty classes specifically.

@catamorphism
Copy link
Contributor

Yeah, classes without dtors are basically treated like records in trans, so I can see why a record with no fields would cause problems. I'll look at this.

@catamorphism
Copy link
Contributor

brson and I agreed we should just forbid classes with no fields, since there are no empty record types either. I will implement that.

@kud1ing
Copy link

kud1ing commented Jun 6, 2012

Does that mean classes are only meant for state-management and if you want to have polymorphic functions, you should go for interfaces/implementions?

@brson
Copy link
Contributor Author

brson commented Jun 6, 2012

@Lenny222 to be clear, I still think empty classes should be allowed eventually. We should just cover the limitation with a compiler error for now instead of a crash.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

3 participants