From ce021e85f43f879b1272af0ecdebe62f9a56c478 Mon Sep 17 00:00:00 2001 From: sergeych Date: Sat, 3 Jan 2026 19:20:40 +0100 Subject: [PATCH] compiler bug with that can cause compilation infinite loop; object is always comparable to self instance or null --- .../kotlin/net/sergeych/lyng/Parser.kt | 17 ++++++++--------- .../kotlin/net/sergeych/lyng/obj/Obj.kt | 4 +++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Parser.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Parser.kt index 416329e..286ca63 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Parser.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Parser.kt @@ -1,5 +1,5 @@ /* - * Copyright 2025 Sergey S. Chernov real.sergeych@gmail.com + * Copyright 2026 Sergey S. Chernov real.sergeych@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -324,15 +324,14 @@ private class Parser(fromPos: Pos) { } '?' -> { - when (currentChar.also { pos.advance() }) { - ':' -> Token("??", from, Token.Type.ELVIS) - '?' -> Token("??", from, Token.Type.ELVIS) - '.' -> Token("?.", from, Token.Type.NULL_COALESCE) - '[' -> Token("?(", from, Token.Type.NULL_COALESCE_INDEX) - '(' -> Token("?(", from, Token.Type.NULL_COALESCE_INVOKE) - '{' -> Token("?{", from, Token.Type.NULL_COALESCE_BLOCKINVOKE) + when (currentChar) { + ':' -> { pos.advance(); Token("?:", from, Token.Type.ELVIS) } + '?' -> { pos.advance(); Token("??", from, Token.Type.ELVIS) } + '.' -> { pos.advance(); Token("?.", from, Token.Type.NULL_COALESCE) } + '[' -> { pos.advance(); Token("?[", from, Token.Type.NULL_COALESCE_INDEX) } + '(' -> { pos.advance(); Token("?(", from, Token.Type.NULL_COALESCE_INVOKE) } + '{' -> { pos.advance(); Token("?{", from, Token.Type.NULL_COALESCE_BLOCKINVOKE) } else -> { - pos.back() Token("?", from, Token.Type.QUESTION) } } diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/Obj.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/Obj.kt index a1cc586..cf89fed 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/Obj.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/obj/Obj.kt @@ -1,5 +1,5 @@ /* - * Copyright 2025 Sergey S. Chernov real.sergeych@gmail.com + * Copyright 2026 Sergey S. Chernov real.sergeych@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -149,6 +149,8 @@ open class Obj { // methods that to override open suspend fun compareTo(scope: Scope, other: Obj): Int { + if( other === this) return 0 + if( other === ObjNull ) return 2 scope.raiseNotImplemented() }