Skip to content

[SR-5324] Better diagnostic when instance member of outer type is referenced from nested type #47898

@jckarter

Description

@jckarter
Previous ID SR-5324
Radar rdar://problem/33015870
Original Reporter @jckarter
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, StarterBug
Assignee kacperh (JIRA)
Priority Medium

md5: 89ed2369cd8bd72c149a19b747b77277

Issue Description:

If you attempt something like this:

struct Outer {
  var outer: Int

  struct Inner {
    var inner: Int

    func sum() -> Int {
      return inner + outer
    }
  }
}

then you get a somewhat confusing error message:

foo.swift:8:22: error: instance member 'outer' cannot be used on type 'Outer'
      return inner + outer
                     ^~~~~

since the member isn't really being used on the outer type, but on an instance of the inner type. A specialized diagnostic that said "instance member 'outer' of type 'Outer' cannot be accessed on instance of nested type 'Outer.Inner'" would be easier to understand.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions