Skip to content
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

#91 Fixed force cast conversion #92

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Assets/Tests/KotlinTokenizer/expressions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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] {
Expand Down