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-12248] <unknown>
diagnostic location regarding Codable
derived conformances
#54675
Comments
@swift-ci create |
For anybody that wants to take this up, the place where we're diagnosing this is currently way down in `checkRedeclaration` which resides in TypeCheckDeclPrimary. Look for the reference to `diag::invalid_redecl`. Above that reference, you'll notice we're checking to see if the decl is an implicit initializer, then emitting a specialized diagnostic. The same thing needs to be done, but for non-initializers. Add another branch above this one and check if `current` is implicit, then emit a specialized diagnostic that calls out the fact that the variable is synthesized. Make sure not to diagnose the synthesized ValueDecl itself or there won't be a valid source location to attach the diagnostic to - you can probably diagnose the enclosing declaration context for that declaration. |
Comment by Hassan ElDesouky (JIRA) @CodaFi Is this bug has been resolved? Because I can't reproduce the bug. |
hassaneldesouky (JIRA User) I have a master compiler and I still get it. Perhaps something else is going wrong before you're able to see this diagnostic. |
Comment by Hassan ElDesouky (JIRA) @CodaFi this what happens when I run the test provided in the description |
You're not using the just-built swift in that command line (unless you happen to have your environment setup to point into your build directory). This does not reproduce on a 5.1 compiler. |
Comment by Hassan ElDesouky (JIRA) Thank you for making me notices that! |
Comment by Hassan ElDesouky (JIRA) @CodaFi This is completely not related to the issue but I'm not able to build the compiler (master) branch. Here's the error: /home/hassaneldesouky/Desktop/swift-source/swift/lib/IRGen/IRGenDebugInfo.cpp:663:78: error: too few arguments to function call, expected 5, have 4
DBuilder.createModule(Parent, Name, ConfigMacros, RemappedIncludePath);
~~~~~~~~~~~~~~~~~~~~~ ^
/home/hassaneldesouky/Desktop/swift-source/llvm-project/llvm/include/llvm/IR/DIBuilder.h:741:5: note: 'createModule' declared here
DIModule *createModule(DIScope *Scope, StringRef Name,
^
/home/hassaneldesouky/Desktop/swift-source/swift/lib/IRGen/IRGenDebugInfo.cpp:1718:38: error: too many arguments to function call, expected at most 13, have 15
/* RangesBaseAddress */ false, Sysroot, SDK);
^~~~~~~~~~~~
/home/hassaneldesouky/Desktop/swift-source/llvm-project/llvm/include/llvm/IR/DIBuilder.h:138:5: note: 'createCompileUnit' declared here
DICompileUnit *
^
2 errors generated. |
Comment by Hassan ElDesouky (JIRA) @CodaFi I reverted to an older commit and managed to build. Anyways, can you please explain what do you mean by the sentence "Make sure not to diagnose the synthesized ValueDecl itself or there won't be a valid source location to attach the diagnostic to - you can probably diagnose the enclosing declaration context for that declaration."? I tried adding an if statement to check `if (current->isImplicit())` but I found out this is wrong/ incomplete. |
Seems like you have a mismatched LLVM-project checkout. This happens from time-to-time (when we merge master-next to master, for example). Just run
and rebuild with
and everything'll work out. |
To the second question: When you use the decl-based diagnostics entry point, if you try to diagnose an implicit decl you'll come up with a diagnostic that has an invalid source location (because there's literally no location in source for the declaration!). The idea was that if you detect such a case, you should walk to the nearest non-synthesized declaration context and diagnose that instead. |
Comment by Hassan ElDesouky (JIRA) @CodaFi Thank you so much for helping me build the project. Everything is working fine right now! I understand what is the problem now. However, I have two inquiries:
2. When debugging this part of code I found out an interesting thing for me and it's... This `else` block is always getting called first and I don't know why![]( Even after I put another if branch to check to if the |
hassaneldesouky (JIRA User) I think a simple replace of the else clause here TypeCheckDeclPrimary#L714 for something like `else if (![](current->isImplicit() && )other->isImplicit())` should fix the problem |
Comment by Hassan ElDesouky (JIRA) Thank you so much man! I’ll try to use this ❤️ |
Comment by Hassan ElDesouky (JIRA) PR is merged #31037 |
Attachment: Download
Environment
Current apple/swift master: 9600b97
Additional Detail from JIRA
md5: 248ea873711e653b56c1bb05a0820282
Issue Description:
I suspect that the "<unknown>" source locations come from declarations synthesized by
Codable
derived conformances. This issue seems low-priority.The text was updated successfully, but these errors were encountered: