-
Notifications
You must be signed in to change notification settings - Fork 266
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
Fix C# codegen for tail-recursive member functions #2205
Conversation
752719b
to
461791a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bien trouvé !
@@ -1331,7 +1331,9 @@ protected class ClassWriter : IClassWriter { | |||
protected override ConcreteSyntaxTree EmitTailCallStructure(MemberDecl member, ConcreteSyntaxTree wr) { | |||
Contract.Assume((member is Method m0 && m0.IsTailRecursive) || (member is Function f0 && f0.IsTailRecursive)); // precondition | |||
if (!member.IsStatic && !NeedsCustomReceiver(member)) { | |||
wr.WriteLine("var _this = this;"); | |||
var receiverType = member.EnclosingClass is DatatypeDecl dt ? | |||
"_I" + dt.CompileName + TypeParameters(SelectNonGhost(dt, dt.TypeArgs)) : "var"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, since the fields stores an interface, you need to provide the interface for the base type. Nice and easy fix.
var receiverType = member.EnclosingClass is DatatypeDecl dt ? DtTypeName(dt) : "var"; | ||
wr.WriteLine($"{receiverType} _this = this;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var receiverType = member.EnclosingClass is DatatypeDecl dt ? DtTypeName(dt) : "var"; | |
wr.WriteLine($"{receiverType} _this = this;"); | |
wr.Write(member.EnclosingClass is DatatypeDecl dt ? DtTypeName(dt) : "var"); | |
wr.WriteLine(" _this = this;"); |
Closes #2173.