odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.1k stars 550 forks source link

Compiler freezes on access to member function of struct type #3801

Closed dllouw closed 4 days ago

dllouw commented 1 week ago

Context

Compiler freezes when calling a function that is a member of a struct type instead of a struct instance.

Operating System & Odin Version: Odin: dev-2024-06:bad4a6237 OS: Ubuntu 24.04 LTS, Linux 6.8.0-35-generic CPU: AMD Ryzen 7 3800X 8-Core Processor RAM: 64217 MiB Backend: LLVM 18.1.3

Expected Behavior

Some type of compiler time error.

Current Behavior

No error, compiler just hangs.

Steps to Reproduce

Tring to compile this will hang the compiler:

Foo :: struct ($T: typeid) {
    bar: proc (x: $T) -> T
}
main :: proc() }
    foo := Foo(typeid) { proc (_: typeid) {} }
    // normal access of a member function of the struct instance
    foo.bar(int) // this works
    // now a typo where we have Foo instead of foo
    Foo.bar(int) // this freezes the compiler
}

Failure Logs

n/a

Kelimion commented 4 days ago

After correcting the typo (main :: proc }) and adding a comma after -> T, I was able to replicate this:

Foo :: struct ($T: typeid) {
    bar: proc (x: $T) -> T,
}
main :: proc() {
    foo := Foo(typeid) { proc (_: typeid) {} }
    // normal access of a member function of the struct instance
    foo.bar(int) // this works
    // now a typo where we have Foo instead of foo
    Foo.bar(int) // this freezes the compiler
}
blob1807 commented 4 days ago

If I'm understanding it right, this is a duplicate of https://github.com/odin-lang/Odin/issues/3471

gingerBill commented 4 days ago

Fixed in 52ea63f89c7d7c9ff081ab678f9c206e9775a032