Skip to content

Semantic: ScopeFlags for a class in a class constructor has ScopeFlags::Constructor #7900

@overlookmotel

Description

@overlookmotel

Input:

class Outer {
  constructor() {
    class Inner {}
  }
}

Semantic sets ScopeFlags for class Inner {} as StrictMode | Constructor. I believe this is a mistake. It should just be StrictMode.

Weirdly I cannot replicate this in playground (playground). But on latest main, when I print ScopeFlags for all scopes I get this:

ScopeId(0): Program: ScopeFlags(StrictMode | Top)
ScopeId(1): Class(Outer): ScopeFlags(StrictMode)
ScopeId(2): Function(<anonymous>): ScopeFlags(StrictMode | Function | Constructor)
ScopeId(3): Class(Inner): ScopeFlags(StrictMode | Constructor)

Debug code:

let scopes = semantic.scopes();
let nodes = semantic.nodes();
#[allow(clippy::cast_possible_truncation)]
for i in 0..scopes.len() {
    let scope_id = ScopeId::new(i as u32);
    let flags = scopes.get_flags(scope_id);
    let node_id = scopes.get_node_id(scope_id);
    let kind = nodes.get_node(node_id).kind();
    let name = kind.debug_name();
    println!("{scope_id:?}: {name}: {flags:?}");
}

As this isn't visible on playground, is this the result of a very recent change? Or is there something else funny going on?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions