You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: 4d348d1c15acacdeb52ce89ee3d3eb26
duplicates:
SR-1846 "Variable used in its own initial value" error when using a function (not a variable) of the same name
Issue Description:
If I have a function foo(label:) and I try and create a var foo I can't initialize it with a call to foo(label: x). This seems to be a bug in the lint that detects referencing a variable in its own initializer, because the compiler doesn't actually treat the variable and function as ambiguous.
This fails:
funcfoo(label: Int) -> Int { returnlabel + 1 }
varfoo = foo(label: 42) // error: variable used within its own initial value
I think we need to patch `parseExprIdentifier()` in the parser to not diagnose this. This will then result in an UnresolvedDeclRefExpr being passed up and later diagnosed as "ambiguous use of...", but we could also patch `resolveDeclRefExpr()` in the type checker to check if LHS is a variable and RHS is a func and allow that, otherwise if both LHS and RHS is a variable (which has the same name/decl) then we emit the existing diagnostics.
I have a small patch ready for this, if this is a reasonable approach. cc @rintaro
Environment
Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Additional Detail from JIRA
md5: 4d348d1c15acacdeb52ce89ee3d3eb26
duplicates:
Issue Description:
If I have a function
foo(label:)
and I try and create avar foo
I can't initialize it with a call tofoo(label: x)
. This seems to be a bug in the lint that detects referencing a variable in its own initializer, because the compiler doesn't actually treat the variable and function as ambiguous.This fails:
This works:
The text was updated successfully, but these errors were encountered: