Skip to content

[BUG] Lookup of emitted definition differs from what's apparent in source code #704

Open
@JohelEGP

Description

@JohelEGP

Title: Type-scope object alias of nested type needs explicit qualification.

Description:

This is relevant to type-scope object alias
emitted during Phase 2 "Cpp2 type definitions and function declarations"
(all of them if #700 isn't fixed).

Lookup for the variable's type doesn't include the declaring class
because t:: hasn't been parsed.
Worse, there is a mismatch if lookup finds something else.

Of course, a: t::u == u(); would work,
but you wouldn't guess it just looking at Cpp2.

Minimal reproducer (https://cpp2.godbolt.org/z/oKP3Yev44):

// u: @struct type = { }
t: @struct type = {
  u: @struct type = { }
  a: u == u();
}
main: () = { }
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result: A well-formed program.

Actual result and error:

Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"


class t;
  

//=== Cpp2 type definitions and function declarations ===========================

// u: @struct type = { }
class t {
  public: class u {};
  public: static const u a;
};
auto main() -> int;


//=== Cpp2 function definitions =================================================


  inline constexpr u t::a = u();

auto main() -> int{}
Output:

When lookup doesn't find u:

main.cpp2:4:20: error: 'u' does not name a type

When lookup finds another u:

main.cpp2:4:22: error: conflicting declaration 'constexpr const u t::a'
build/main.cpp:17:26: note: previous declaration as 'const t::u t::a'
   17 |   public: static const u a;
      |                          ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions