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

Warn isolated type variables #446

Open
mtshiba opened this issue Aug 2, 2023 · 0 comments
Open

Warn isolated type variables #446

mtshiba opened this issue Aug 2, 2023 · 0 comments

Comments

@mtshiba
Copy link
Member

mtshiba commented Aug 2, 2023

Describe the code issue?

Recently, I implemented warn_isolated_vars.

impl TyVarCache {
    /// Warn when a type does not need to be a type variable, such as `|T| T -> Int` (it should be `Obj -> Int`).
    ///
    /// TODO: This warning is currently disabled because it raises a false warning in cases like `|T|(x: T) -> (y: T) -> (x, y)`.
    pub fn warn_isolated_vars(&self, ctx: &Context) {
        for (name, vi) in self.var_infos.iter() {
            let refs = &ctx.index().get_refs(&vi.def_loc).unwrap().referrers;
            if refs.len() == 1 {
                let warn = TyCheckError::unnecessary_tyvar_warning(
                    ctx.cfg.input.clone(),
                    line!() as usize,
                    vi.def_loc.loc,
                    name.inspect(),
                    ctx.caused_by(),
                );
                ctx.shared().warns.push(warn);
            }
        }
    }
}

As noted in the TODO, this is not currently enabled as it may cause a false warning. I can rewrite it correctly, but for now I have other tasks to do, so I will leave it as a code issue.

Additional context

No response

Erg version

0.6.18.nightly

Python version

None

OS

None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant