From 6539b9deffb4df612a8c72a7558292903ff5c12c Mon Sep 17 00:00:00 2001 From: sergeych Date: Wed, 4 Feb 2026 00:24:19 +0300 Subject: [PATCH] Fix wasm map usage and ignore annotation --- .../commonMain/kotlin/net/sergeych/lyng/Compiler.kt | 10 ++++++---- .../kotlin/net/sergeych/lyng/obj/ObjClass.kt | 12 ++++++------ .../lyng/highlight/MapLiteralHighlightTest.kt | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt index bcbdba4..a2bc48d 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt @@ -364,13 +364,15 @@ class Compiler( for (base in allBaseNames) { val info = resolveCompileClassInfo(base) ?: continue for ((name, id) in info.fieldIds) { - val prev = fieldIds.putIfAbsent(name, id) - if (prev != null && prev != id) fieldConflicts.add(name) + val prev = fieldIds[name] + if (prev == null) fieldIds[name] = id + else if (prev != id) fieldConflicts.add(name) if (id > maxFieldId) maxFieldId = id } for ((name, id) in info.methodIds) { - val prev = methodIds.putIfAbsent(name, id) - if (prev != null && prev != id) methodConflicts.add(name) + val prev = methodIds[name] + if (prev == null) methodIds[name] = id + else if (prev != id) methodConflicts.add(name) if (id > maxMethodId) maxMethodId = id } } diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/ObjClass.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/ObjClass.kt index c0d361f..6b69e1b 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/ObjClass.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/ObjClass.kt @@ -428,14 +428,14 @@ open class ObjClass( if (rec.type != ObjRecord.Type.Field && rec.type != ObjRecord.Type.ConstructorField) continue if (rec.visibility == Visibility.Private) continue val id = rec.fieldId ?: cls.assignFieldId(name, rec) - result.putIfAbsent(name, id) + if (!result.containsKey(name)) result[name] = id } cls.classScope?.objects?.forEach { (name, rec) -> if (rec.isAbstract) return@forEach if (rec.type != ObjRecord.Type.Field && rec.type != ObjRecord.Type.ConstructorField) return@forEach if (rec.visibility == Visibility.Private) return@forEach val id = rec.fieldId ?: cls.assignFieldId(name, rec) - result.putIfAbsent(name, id) + if (!result.containsKey(name)) result[name] = id } } return result @@ -451,7 +451,7 @@ open class ObjClass( rec.type != ObjRecord.Type.Property && rec.type != ObjRecord.Type.Delegated) continue val id = rec.methodId ?: cls.assignMethodId(name, rec) - result.putIfAbsent(name, id) + if (!result.containsKey(name)) result[name] = id } cls.classScope?.objects?.forEach { (name, rec) -> if (!includeAbstract && rec.isAbstract) return@forEach @@ -460,7 +460,7 @@ open class ObjClass( rec.type != ObjRecord.Type.Property && rec.type != ObjRecord.Type.Delegated) return@forEach val id = rec.methodId ?: cls.assignMethodId(name, rec) - result.putIfAbsent(name, id) + if (!result.containsKey(name)) result[name] = id } } return result @@ -497,7 +497,7 @@ open class ObjClass( rec.type != ObjRecord.Type.Delegated ) continue val id = rec.methodId ?: cls.assignMethodId(name, rec) - methodIdMap.putIfAbsent(name, id) + if (!methodIdMap.containsKey(name)) methodIdMap[name] = id if (id > maxId) maxId = id } cls.classScope?.objects?.forEach { (name, rec) -> @@ -506,7 +506,7 @@ open class ObjClass( rec.type != ObjRecord.Type.Delegated ) return@forEach val id = rec.methodId ?: cls.assignMethodId(name, rec) - methodIdMap.putIfAbsent(name, id) + if (!methodIdMap.containsKey(name)) methodIdMap[name] = id if (id > maxId) maxId = id } } diff --git a/lynglib/src/commonTest/kotlin/net/sergeych/lyng/highlight/MapLiteralHighlightTest.kt b/lynglib/src/commonTest/kotlin/net/sergeych/lyng/highlight/MapLiteralHighlightTest.kt index f7c66b1..cf9d7f1 100644 --- a/lynglib/src/commonTest/kotlin/net/sergeych/lyng/highlight/MapLiteralHighlightTest.kt +++ b/lynglib/src/commonTest/kotlin/net/sergeych/lyng/highlight/MapLiteralHighlightTest.kt @@ -21,7 +21,7 @@ import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertTrue -@Ignore("Highlight tests postponed until ScriptTest baseline is restored") +@Ignore class MapLiteralHighlightTest { private fun spansToLabeled(text: String, spans: List): List> =