Skip to content

Commit

Permalink
Fixed duplicating fields when overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
anti-social committed Sep 23, 2021
1 parent b3bb01c commit 9df6bb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ allprojects {
}
}

tasks.findByName("nativeTest")?.run {
outputs.upToDateWhen { false }
}
tasks.findByName("jvmTest")?.run {
outputs.upToDateWhen { false }

Expand Down
13 changes: 9 additions & 4 deletions src/commonMain/kotlin/dev/evo/elasticmagic/Document.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,24 @@ class BoundJoinField(
*/
abstract class FieldSet : Named {
private val fields: ArrayList<AnyField> = arrayListOf()
private val fieldsByName: HashMap<String, AnyField> = hashMapOf()
private val fieldsByName: HashMap<String, Int> = hashMapOf()

internal fun addField(field: AnyField) {
fields.add(field)
fieldsByName[field.getFieldName()] = field
val existingFieldIx = fieldsByName[field.getFieldName()]
if (existingFieldIx != null) {
fields[existingFieldIx] = field
} else {
fieldsByName[field.getFieldName()] = fields.size
fields.add(field)
}
}

internal fun getAllFields(): List<AnyField> {
return fields.toList()
}

internal fun getFieldByName(name: String): AnyField? {
return fieldsByName[name]
return fields[fieldsByName[name] ?: return null]
}

fun <T> field(
Expand Down

0 comments on commit 9df6bb3

Please sign in to comment.