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
Xcode v8.0 beta 3 (8S174q)
Apple Swift version 3.0 (swiftlang-800.0.34.6 clang-800.0.33)
Target: x86_64-apple-macosx10.9
Additional Detail from JIRA
Votes
0
Component/s
Labels
Improvement
Assignee
None
Priority
Medium
md5: 1e7ba604aeb3dad259864c2898eef77d
duplicates:
SR-773 Using Array initializer syntax with nested types causes bad error message
Issue Description:
The shorthand of [T] for Array<T> didn't seem to work when trying to initialize the array when T is a nested type.
Details
Given a class with a nested struct
classC {
structS {
lettitle: String
}
}
I want to use it from another class, but initializing this array property using the shorthand didn't work like I expected.
Here were a few steps that I went through (based on the error messages and Fixits):
Step 1:
I first tries this, to make a stored property that's initialized to the empty array.
classC2 {
varstate = [C.S]() // <-- Error: Invalid use of '()' to call a value of non-function type '[UKUploadGroupTracker.UploadGroupInfo.Type]'// Fixit: Delete the ()
}
Step 2:
So, try the suggested Fixit, deleting the ().
classC2 {
varstate = [C.S] // <-- Error: Expected member name or constructor call after type name// Fixit: add () inside the ]
}
Step 3:
Try that Fixit, adding the () inside the ].
classC2 {
varstate = [C.S()] // <-- Error: Cannot invoke value of type 'C.S.Type' with argument list '()'
}
Step 4:
Use a different syntax to initialize the array. This does work.
classC2 {
varstate: [C.S] = []
}
Step 5:
Use another different syntax to initialize the array. This works also.
classC2 {
varstate = Array<C.S>()
}
Expect
I expected my first attempt in Step 1 to just be shorthand for Step 5, but Step 1 didn't work, and Step 5 did.
Notes
It doesn't work to do var state = [C.S]() inside a func in that class either.
The text was updated successfully, but these errors were encountered:
Environment
Xcode v8.0 beta 3 (8S174q)
Apple Swift version 3.0 (swiftlang-800.0.34.6 clang-800.0.33)
Target: x86_64-apple-macosx10.9
Additional Detail from JIRA
md5: 1e7ba604aeb3dad259864c2898eef77d
duplicates:
Issue Description:
The shorthand of
[T]
forArray<T>
didn't seem to work when trying to initialize the array whenT
is a nested type.Details
Given a class with a nested struct
I want to use it from another class, but initializing this array property using the shorthand didn't work like I expected.
Here were a few steps that I went through (based on the error messages and Fixits):
Step 1:
I first tries this, to make a stored property that's initialized to the empty array.
Step 2:
So, try the suggested Fixit, deleting the
()
.Step 3:
Try that Fixit, adding the
()
inside the]
.Step 4:
Use a different syntax to initialize the array. This does work.
Step 5:
Use another different syntax to initialize the array. This works also.
Expect
I expected my first attempt in Step 1 to just be shorthand for Step 5, but Step 1 didn't work, and Step 5 did.
Notes
var state = [C.S]()
inside a func in that class either.The text was updated successfully, but these errors were encountered: