rhaiscript / lsp

Language server for Rhai.
Apache License 2.0
48 stars 5 forks source link

Panic after removing types #84

Closed tamasfe closed 2 years ago

tamasfe commented 2 years ago
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', crates/rhai-hir/src/hir/resolve/types.rs:566:54

Types are handled slightly differently compared to symbols, the relationships (references/aliases) between them are not as clear and aren't tracked. So when a type is removed we might end up having dangling references to it which currently result in a panic.

We either need to track references, properly update them and keep the current panicking behaviour to catch bugs (the hard way), or return the builtin unknown type any time a type is requested that does not exist (the easy way).

schungx commented 2 years ago

Speaking of "dangling references" worry me... is this from unsafe Rust? Because safe Rust should really have them...

tamasfe commented 2 years ago

I don't think there's any significant unsafe code right now. Most data in the HIR is stored in slotmaps (arenas), hierarchies and references are achieved by storing indexes to data.

schungx commented 2 years ago

Ah ok. So you mean an index that refers to data that is no longer valid. I suppose you can just substitute ? for now?

tamasfe commented 2 years ago

Alright I just did that, it's in the phase where we resolve all type aliases, so it's a form of garbage collection. I did not touch related code anywhere else, so we will still panic on bugs where types are expected to exist.