Compare commits
No commits in common. "8a560f54177c2040af5ab5ba63175bd805b0c539" and "c3c0a3292bce47b531c86ca9ca9d29627b02404a" have entirely different histories.
8a560f5417
...
c3c0a3292b
@ -172,7 +172,6 @@ class Compiler(
|
||||
private val callReturnTypeDeclByRef: MutableMap<CallRef, TypeDecl> = mutableMapOf()
|
||||
private val callableReturnTypeByScopeId: MutableMap<Int, MutableMap<Int, ObjClass>> = mutableMapOf()
|
||||
private val callableReturnTypeByName: MutableMap<String, ObjClass> = mutableMapOf()
|
||||
private val callableReturnTypeDeclByName: MutableMap<String, TypeDecl> = mutableMapOf()
|
||||
private val lambdaReturnTypeByRef: MutableMap<ObjRef, ObjClass> = mutableMapOf()
|
||||
private val lambdaCaptureEntriesByRef: MutableMap<ValueFnRef, List<net.sergeych.lyng.bytecode.LambdaCaptureEntry>> =
|
||||
mutableMapOf()
|
||||
@ -4314,17 +4313,14 @@ class Compiler(
|
||||
is MapLiteralRef -> inferMapLiteralTypeDecl(ref)
|
||||
is ConstRef -> inferTypeDeclFromConst(ref.constValue)
|
||||
is CallRef -> {
|
||||
val targetName = when (val target = ref.target) {
|
||||
is LocalVarRef -> target.name
|
||||
is FastLocalVarRef -> target.name
|
||||
is LocalSlotRef -> target.name
|
||||
else -> null
|
||||
}
|
||||
if (targetName != null) {
|
||||
callableReturnTypeDeclByName[targetName]?.let { return it }
|
||||
}
|
||||
inferCallReturnClass(ref)?.let { TypeDecl.Simple(it.className, false) }
|
||||
?: run {
|
||||
val targetName = when (val target = ref.target) {
|
||||
is LocalVarRef -> target.name
|
||||
is FastLocalVarRef -> target.name
|
||||
is LocalSlotRef -> target.name
|
||||
else -> null
|
||||
}
|
||||
if (targetName != null && targetName.firstOrNull()?.isUpperCase() == true) {
|
||||
TypeDecl.Simple(targetName, false)
|
||||
} else {
|
||||
@ -8161,10 +8157,6 @@ class Compiler(
|
||||
inferredReturnClass
|
||||
}
|
||||
}
|
||||
val inferredReturnDecl = returnTypeDecl ?: inferredReturnClass?.let { TypeDecl.Simple(it.className, false) }
|
||||
if (declKind != SymbolKind.MEMBER && inferredReturnDecl != null) {
|
||||
callableReturnTypeDeclByName[name] = inferredReturnDecl
|
||||
}
|
||||
val fnStatements = rawFnStatements?.let { stmt ->
|
||||
if (!compileBytecode) return@let stmt
|
||||
val paramKnownClasses = mutableMapOf<String, ObjClass>()
|
||||
|
||||
@ -732,8 +732,7 @@ private class Parser(fromPos: Pos, private val interpolationEnabled: Boolean = t
|
||||
}
|
||||
val expanded = mutableListOf<Token>()
|
||||
expanded += Token("(", tokenPos, Token.Type.LPAREN)
|
||||
expanded += Token("", tokenPos, Token.Type.STRING)
|
||||
var emittedPieces = 1
|
||||
var emittedPieces = 0
|
||||
for (chunk in chunks) {
|
||||
val pieceTokens = when (chunk) {
|
||||
is StringChunk.Literal -> {
|
||||
@ -756,6 +755,9 @@ private class Parser(fromPos: Pos, private val interpolationEnabled: Boolean = t
|
||||
expanded += pieceTokens
|
||||
emittedPieces++
|
||||
}
|
||||
if (emittedPieces == 0) {
|
||||
expanded += Token("", tokenPos, Token.Type.STRING)
|
||||
}
|
||||
expanded += Token(")", tokenPos, Token.Type.RPAREN)
|
||||
|
||||
val first = expanded.first()
|
||||
@ -764,21 +766,10 @@ private class Parser(fromPos: Pos, private val interpolationEnabled: Boolean = t
|
||||
}
|
||||
|
||||
private fun parseEmbeddedExpressionTokens(text: String, exprPos: Pos): List<Token> {
|
||||
val tokens = try {
|
||||
parseLyng(Source(exprPos.source.fileName, text), interpolationEnabled)
|
||||
} catch (e: ScriptError) {
|
||||
throw ScriptError(remapEmbeddedPos(exprPos, e.pos), e.errorMessage, e)
|
||||
}
|
||||
val tokens = parseLyng(Source(exprPos.source.fileName, text), interpolationEnabled)
|
||||
if (tokens.isEmpty()) return emptyList()
|
||||
val withoutEof = if (tokens.last().type == Token.Type.EOF) tokens.dropLast(1) else tokens
|
||||
return withoutEof.map { it.copy(pos = remapEmbeddedPos(exprPos, it.pos)) }
|
||||
}
|
||||
|
||||
private fun remapEmbeddedPos(exprPos: Pos, embeddedPos: Pos): Pos {
|
||||
if (embeddedPos.line < 0 || embeddedPos.column < 0) return exprPos
|
||||
val line = exprPos.line + embeddedPos.line
|
||||
val column = if (embeddedPos.line == 0) exprPos.column + embeddedPos.column else embeddedPos.column
|
||||
return Pos(exprPos.source, line, column)
|
||||
return withoutEof
|
||||
}
|
||||
|
||||
private fun readInterpolationExprText(start: Pos): String {
|
||||
|
||||
@ -21,7 +21,6 @@ import com.ionspin.kotlin.bignum.decimal.BigDecimal
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
class DecimalModuleTest {
|
||||
@Test
|
||||
@ -267,32 +266,4 @@ class DecimalModuleTest {
|
||||
assert(X == 42)
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDecimalStringInterpolation() = runTest {
|
||||
eval(
|
||||
$$"""
|
||||
import lyng.decimal
|
||||
var X = "2".d
|
||||
var re = 50.d
|
||||
var im = X
|
||||
val s = "$re + ${im}i"
|
||||
assertEquals("50 + 2i", s)
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDecimalInterpolationSyntaxErrorKeepsOriginalSourcePosition() = runTest {
|
||||
val ex = assertFailsWith<ScriptError> {
|
||||
eval(
|
||||
$$"""
|
||||
import lyng.decimal
|
||||
var re = 50.d
|
||||
val s = "${re + }"
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
assertEquals(2, ex.pos.line)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user