swiftlang/swift

[SR-10295] Unexpected ambiguity error when trying to use variable with the same name as an instance member

Open

#52,695 opened on Apr 3, 2019

View on GitHub
 (3 comments) (0 reactions) (1 assignee)Swift (10,719 forks)batch import
bugcompilerdiagnostics qualitygood first issue

Repository metrics

Stars
 (69,989 stars)
PR merge metrics
 (Avg merge 8d 17h) (510 merged PRs in 30d)

Description

Previous ID SR-10295
Radar rdar://problem/45572606
Original Reporter @xedin
Type Bug
Status In Progress
Resolution
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee @theblixguy
Priority Medium

md5: 350070c7174a52610d975e704164ed3e

relates to:

  • SR-1846 "Variable used in its own initial value" error when using a function (not a variable) of the same name

Issue Description:

Consider following example:

struct S {
  func foo(x: Int) {}

  func bar() {
    let foo = foo(x: 42)
  }
}

It produces following error:

variable used within its own initial value

Which doesn't really make much sense, instead it should produce an error which suggests to add `self.` before method or variable use e.g. `let foo = self.foo(x: 42)`

Contributor guide