Skip to content

Commit

Permalink
#91 Fixed force cast conversion
Browse files Browse the repository at this point in the history
angelolloqui authored Feb 7, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents d96fff5 + 9eecf62 commit 0fbe857
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Assets/Tests/KotlinTokenizer/expressions.kt
Original file line number Diff line number Diff line change
@@ -6,3 +6,5 @@ val text = label ?: "default"
service.deleteObject()
this.service.fetchData()?.user?.name?.size
this.data.filter { it.item?.value == 1 }.map { it.key }.firstOrNull()?.name?.size
this.object = data as ObjectType
this.object = data as? ObjectType
4 changes: 4 additions & 0 deletions Assets/Tests/KotlinTokenizer/expressions.swift
Original file line number Diff line number Diff line change
@@ -12,3 +12,7 @@ _ = service.deleteObject()
// Optional chaning
self.service.fetchData()?.user.name?.count
self.data.filter { $0.item?.value == 1 }.map { $0.key }.first?.name.count

// Type casting
self.object = data as! ObjectType
self.object = data as? ObjectType
14 changes: 14 additions & 0 deletions Sources/SwiftKotlinFramework/KotlinTokenizer.swift
Original file line number Diff line number Diff line change
@@ -833,6 +833,20 @@ public class KotlinTokenizer: SwiftTokenizer {
}
return tokens
}

open override func tokenize(_ expression: TypeCastingOperatorExpression) -> [Token] {
switch expression.kind {
case let .forcedCast(expr, type):
return [
tokenize(expr),
[expression.newToken(.keyword, "as")],
tokenize(type, node: expression)
].joined(token: expression.newToken(.space, " "))
default:
return super.tokenize(expression)
}
}


// MARK: - Types
open override func tokenize(_ type: ArrayType, node: ASTNode) -> [Token] {

0 comments on commit 0fbe857

Please sign in to comment.