AzureMarker / intellij-lalrpop

Jetbrains plugin for the LALRPOP parser-generator
MIT License
16 stars 2 forks source link

Investigate using type aliases instead of unit structs when comparing explicit vs inferred types #31

Open AzureMarker opened 3 years ago

AzureMarker commented 3 years ago

Related discussions:

Currently the WrongInferredTypeInspection uses unit structs in place of the generic types when comparing the explicit (written by the user in the lalrpop file) and inferred (via the plugin code) types of a nonterminal.

Example nonterminal:

// alternative type resolves to std::collections::HashMap<K, V>
MyNonterminal<K, V>: HashMap<K, V> = ...;

Current behavior:

// imports

struct K;
struct V;

type T1 = HashMap<K, V>;
type T2 = std::collections::HashMap<K, V>;

Proposed behavior:

// imports

type T1<K, V> = HashMap<K, V>;
type T2<K, V> = std::collections::HashMap<K, V>;

The current behavior fails when the type has restrictions on the generics it allows. For example if HashMap always requires Hash for the first generic this might fail (but this hasn't really been tested). The proposed behavior is more intuitive, as Rust type aliases are designed to not care about the type restrictions on the generics, but is trickier to implement.

In the second related discussion @dblanovschi points out some possible issues with the proposed behavior, such as the difficulty in getting an intellij-rust Substitution object to compare the types with. The proposed method is promising, but requires some more investigation before we know if it's possible and what the tradeoffs are.