-
Notifications
You must be signed in to change notification settings - Fork 198
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
added code to remove default arguments from overridden function definition #89
Conversation
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.
Approved and changed with some additional changes (see comments)
@@ -0,0 +1,5 @@ | |||
class Test { | |||
override func dostuff(x:Int = 5) { | |||
} |
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.
great! this is the kind of tests useful. I am going to add a second method with default arguments not overriden to check they are not removed in that case
@@ -0,0 +1,5 @@ | |||
class Test { | |||
override func dostuff(x:Int = 5) { |
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.
Very minor, but it is good practice to try to keep formatting as close as possibe to the standard accepted Swift. In this case, the space between x
and Int
. Not a reason to reject the PR, but just a comment (I changed it myself)
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.
Ah, yes. I started using swift without spaces between label and type in arguments, but switched a while back, but still forget sometimes...
@@ -1078,3 +1084,32 @@ public struct InvertedCondition: ASTTokenizable { | |||
public let condition: Condition | |||
} | |||
|
|||
// function used to remove default arguments from override functions, since kotlin doesn't have them | |||
private func removeDefaultArgsFromParameters(tokens:[Token]) -> [Token] { | |||
var newTokens = [Token]() |
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.
I am moving this function to a private method inside the main class. There is no real benefit of it since we are not inheriting for now, but just for consistency with the rest.
let bodyTokens = declaration.body.map(tokenize) ?? [] | ||
|
||
return [ | ||
if modifierTokens.contains(where:{$0.value == "override" }) { |
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.
Instead of checking the modifiers directly, I am going to move it to an extension like the isStatic
because it is a handy check to be used by others in future (and safer to check the type directly rather than the text value)
Merged and created Issue with the sample code for better tracking (#90) |
Great. I'll delete my branch and start a new pull request on a new branch, does that sounds right? PS: Next down the file was a call to something that tranformed function definitions to make operator functions in kotlin by prefixing them with operator_: in swift.
|
Yes, that should be the way to go, each feature in a new branch, always starting from the most recent commit on develop. That way we can merge them in isolation and keep conversations short. |
Regarding your operation question, do you have a concrete example? (Swift version and what is expected/obtained in Kotlin) |
Hi
Yes, I have a ZRect struct with these functions:
func operator_plus(_ a:ZRect) -> ZRect { return ZRect(min:pos + a.pos, max:Max + a.Max) }
swift-only (not translated):
func +(me:ZRect, a:ZRect) -> ZRect { return me.operator_plus(a) }
and in kotlin my setup translates to:
operator fun plus(a: ZRect) : ZRect =
ZRect(min = pos + a.pos, max = Max + a.Max)
it’s not ideal, but good to ensure code code is the same in swift and kotlin.
tor
|
I am not sure I understand why you have that
then this could be translated to Kotlin like:
and in both cases it could be used normally as: Why do you need the artificial |
BTW, there is a related issue #43, maybe we should move the conversation there |
No description provided.