Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5916] Assigning to var from func of same prefix throws compiler error #48475

Closed
sethfri opened this issue Sep 18, 2017 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@sethfri
Copy link

sethfri commented Sep 18, 2017

Previous ID SR-5916
Radar None
Original Reporter @sethfri
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 9 GM, Swift 4

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 4781d149d0eacf05febed6bfea54d200

duplicates:

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

relates to:

  • SR-1687 Swift does not warn about shadowing

Issue Description:

The following throws the compiler error "Variable used within its own initial value", and I can't see why it should.

The problem seems to be with the fact that the constant is named "string" and the func that I'm assigning to it from also starts with "string" (though the full name of the func is obviously "string(at:)"). Please ignore the functionality of the sample code; I've pared it down from a larger project that uses UIViews and IndexPaths instead of Strings and Ints.

struct Foo {

{{ func bar() {}}

{{ let string = string(at: 2)}}

    }

{{ private func string(at index: Int) -> String {}}

{{ return "Test"}}

    }

{{ }}{{}}}

@belkadan
Copy link
Contributor

I feel like we've had this filed before but I can't find anything closer than SR-1687 in either JIRA or Radar. @DougGregor?

@sethfri
Copy link
Author

sethfri commented Dec 21, 2018

@belkadan Your hunch was right 🙂 SR-1846 is what you were thinking of. Resolving this as a dupe of that

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants