Skip to content

Commit

Permalink
#110 Equatable structs should not include type inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
angelolloqui committed Mar 21, 2020
1 parent 62d9ed7 commit 08db8c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Assets/Tests/KotlinTokenizer/structs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct Data {
var text: String
}

struct Person {
struct Person: Equatable {
let name: String
let surname: String
var age: Int
Expand Down
8 changes: 3 additions & 5 deletions Sources/SwiftKotlinFramework/KotlinTokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public class KotlinTokenizer: SwiftTokenizer {
at: bodyStart - 1)
}

if let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList,
!typeInheritanceList.isEmpty,
if let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList.nonEquatable,
typeInheritanceList.isEmpty == false,
let bodyStart = tokens.firstIndex(where: { $0.value == "{"}) {
let clause = TypeInheritanceClause(classRequirement: false, typeInheritanceList: typeInheritanceList)
let inheritanceTokens = tokenize(clause, node: declaration)
Expand Down Expand Up @@ -439,9 +439,7 @@ public class KotlinTokenizer: SwiftTokenizer {

// Simple enums (no tuple values)
if !simpleCases.contains(where: { $0.tuple != nil }) {
let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList.filter {
$0.names.contains { $0.name.textDescription != "Equatable" }
}
let typeInheritanceList = declaration.typeInheritanceClause?.typeInheritanceList.nonEquatable
if typeInheritanceList?.isEmpty == false {
return tokenizeSimpleValueEnum(declaration: declaration, simpleCases: simpleCases)
} else {
Expand Down
7 changes: 7 additions & 0 deletions Sources/SwiftKotlinFramework/utils/AST+Operations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,10 @@ extension GuardStatement {
(bodyStatement is ReturnStatement || bodyStatement is ThrowStatement)
}
}

extension Collection where Iterator.Element == TypeIdentifier {
var nonEquatable: [TypeIdentifier] {
return filter { $0.names.contains { $0.name.textDescription != "Equatable" } }
}
}

0 comments on commit 08db8c0

Please sign in to comment.