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-9213] Incorrect error message when trying to use keypath with tuple #51702
Comments
I think so; this should be straightforward to check for and emit a custom "tuples not implemented yet" message for. |
Never mind, JIRA was acting weird, I have now assigned it to myself! |
I believe I need to emit a different diagnostic in void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {} So: if (auto TE = dyn_cast<TupleExpr>(expr)) { // emit custom diagnostic } Just wondering if I am in the right path 🙂 |
It looks like the current message is coming from |
@belkadan I see! if (currentType) TC.diagnose(componentNameLoc, diag::could_not_find_type_member, currentType, componentName); So, currentType is declared as: Type currentType = rootType; So, perhaps I can do: if (isa<TupleType>(currentType)) { // emit custom diagnostics } |
@jckarter's the real expert, but that approach seems reasonable to me! |
@belkadan okay 🙂 My Mac is still building the compiler, so I haven't tested anything yet, so just waiting for it to finish building. In the meantime, I think it's slightly better to do it before: for (auto &component : KPE->getComponents()) {} So before that for-loop, we can do: if (state == ResolvingType && isa<TupleType>(currentType)) {
// emit diagnostics
return true
} It could also probably be done even earlier, so just before this is declared: SmallString<32> keyPathScratch; because there's no point of continuing forward and we could return early from |
Aha, but what if the second component is a tuple? |
@belkadan Hmm, you mean if we had a nested tuple? let things: (first: Int, second: (third: Int, fourth: Int)) I am under the assumption that |
I was thinking more about something like this:
|
Heh, in fact Alex's original example is one of those. |
PR approved and merged. |
Environment
swift 4.2.1
xcode 10.1
Additional Detail from JIRA
md5: 1221485d8951fe5e52842c6c4d9c0b1d
Issue Description:
struct Hello {
let things: (Int, Int)
}
let keypath: KeyPath<Hello, Int> = \Hello.things.0 // type (Int, Int) has no member 0
{\code}
The text was updated successfully, but these errors were encountered: