Rust-GCC / Rust-GCC/gccrs

Name resolution does not report ambiguities

Open
#2,295 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

I tried this code:

mod foo {
    pub struct Qux;
    pub fn f() -> char { 'a' }
}

mod bar {
    pub struct Qux;
    pub fn f() -> i32 { 15 }
}

fn main() {
    use foo::*;
    use bar::*;
    
    let a: i32 = f();
}

I expected to see this happen:

error[E0659]: `f` is ambiguous (glob import vs glob import in the same module)
  --> test.rs:15:18
   |
15 |     let a: i32 = f();
   |                  ^ ambiguous name
   |
note: `f` could refer to the function imported here
  --> test.rs:12:9
   |
12 |     use foo::*;
   |         ^^^^^^
   = help: consider adding an explicit import of `f` to disambiguate
note: `f` could also refer to the function imported here
  --> test.rs:13:9
   |
13 |     use bar::*; // Ok, no name conflict.
   |         ^^^^^^
   = help: consider adding an explicit import of `f` to disambiguate

warning: unused import: `bar::*`
  --> test.rs:13:9
   |
13 |     use bar::*; // Ok, no name conflict.
   |         ^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error[E0308]: mismatched types
  --> test.rs:15:18
   |
15 |     let a: i32 = f();
   |            ---   ^^^ expected `i32`, found `char`
   |            |
   |            expected due to this

Instead, this happened:

test.rs:15:5: error: expected ‘i32’ got ‘char’
   15 |     let a: i32 = f();
      |     ^~~    ~~~   ~

So the name resolver picks the first declaration of f without reporting about the conflict. I added a type mismatch error to see which one was being picked - but if there is no type error, then gccrs does not emit the name resolution error, which is important here.

Meta
  • What version of Rust GCC were you using, git sha if possible.

533e1ef3ca4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the Rust snippet in the report and inspect the gccrs name-resolution handling for two glob imports that define the same name. Done means the resolver reports an ambiguity for f, identifies both imports, and does not silently select the first declaration.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.