Fixes for primary constructors#3614
Conversation
|
oh, no, I just spent the last week rewriting that part of the decompiler. |
|
I'm sorry I was late with this. Most of it was done days ago but I was having a troublesome week. |
|
Oh, no worries. For me it was a stressful week too, I only finished my refactoring today. |
|
Oh I forgot to mention in the main post but I still had one unsolved issue that isn't part of #3611. It is a variable naming conflict. I had trouble creating a simple case that doesn't involve pattern matching so this will have to do. It only occurs once in my full decompiled code project so it's a low priority. Input private class C8(object obj)
{
public int Test()
{
if (obj is int i)
return i;
return 0;
}
}Output private class C8(object obj)
{
public int Test()
{
object obj = obj; // Name conflict
if (obj is int)
return (int)obj;
return 0;
}
} |
|
Can you extract the changes to |
4db44c9 to
8627386
Compare
|
Done |
|
I am working on this right now... please wait |
8627386 to
1a059d9
Compare
1a059d9 to
22ceb6e
Compare
|
|
||
| public override void VisitParameterDeclaration(ParameterDeclaration parameterDeclaration) | ||
| { | ||
| if (inPrimaryConstructor || parameterDeclaration.Parent is not TypeDeclaration) |
There was a problem hiding this comment.
this looks suspicious... we shouldn't skip those... instead we should just make sure that the correct resolver is used when visiting...
There was a problem hiding this comment.
if you want to prevent a mostly harmless "double visit" you can keep it like this, but I guess the inPrimaryConstructor field is unnecessary, you can just skip if the parent is a TypeDeclaration...
There was a problem hiding this comment.
if we keep it, it needs a comment
if I change your code like this, it still works... so no need to track the primary constructor separately, just visit it in a different context. |
siegfriedpammer
left a comment
There was a problem hiding this comment.
Thank you for spotting this bug/missing transformation... let me know, if you want to make the changes yourself, or how we should continue thanks!
|
I'm trying out your different suggestions and, while removing the |
|
After some more thorough testing just removing the Edit. private class C10<T>(C10<T>.DataType data)
{
public struct DataType { public int Value { get; set; } }
public DataType Data => data;
}Output // Missing type argument V
private class C10<T>(C10<>.DataType data)
{
public struct DataType
{
public int Value { get; set; }
}
public DataType Data => data;
} |
|
that's a different bug; now fixed see 45efc73 |
|
There are also more problems from your new commit. Edit. Moved case to new issue #3617 |
|
Please create issues for new problems, otherwise the problems might get lost in a PR comment, if they are not fixed immediately. Let's keep the discussion on this PR focused on the PR topic. Thanks a lot for your understanding. |
|
Ok, I'll make another issue. Was there anything more you wanted from me in this one? |
…pe annotations to generic types with nested types.
I fixed the underlying issue that the annotations created by the
Yeah, I got it wrong. Sorry!
Yes, you are right, seems like we cannot get rid of the extra state. But could you please use try-finally for the assignments and, add a comment/explanation in the VisitParameterDeclaration override? Thank you very much! |
|
Done. Is that change and comment what you had in mind? |
|
Thank you for your contribution! |
Adds the test cases from #3611 and fixes them.
The changes to
IntroduceUsingDeclarationsfix missing type name qualifiers in primary constructor parameters when the parameter type is or contains a nested type. However, I'm not sure if my changes are the best way to handle it, what do you think?