Fix that const definitions referencing imported consts cannot be loaded (#551)
* We should check the expectedPath against the thrift file name, instead of the full path, which might contain directories. * Addressing the comment for the test case. * Use an existing API of the Location class. * Remove unintentional format change.
This commit is contained in:
Родитель
3c6d80877a
Коммит
ef9b63c8af
|
@ -443,10 +443,9 @@ internal class Linker(
|
|||
if (ix != -1) {
|
||||
val includeName = symbol.substring(0, ix)
|
||||
val qualifiedName = symbol.substring(ix + 1)
|
||||
val expectedPath = "$includeName.thrift"
|
||||
constant = program.includes
|
||||
.asSequence()
|
||||
.filter { p -> p.location.path == expectedPath } // TODO: Should this be ==, or endsWith?
|
||||
.filter { p -> p.location.programName == includeName }
|
||||
.mapNotNull { p -> p.constantMap[qualifiedName] }
|
||||
.firstOrNull()
|
||||
}
|
||||
|
|
|
@ -264,6 +264,47 @@ class LoaderTest {
|
|||
enum.location.path shouldBe listOf("nested", "a.thrift").joinToString(File.separator)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun crazyIncludeReferencedConst() {
|
||||
val nestedDir = File(tempDir, "nested").apply { mkdir() }
|
||||
val fileNestedAThrift = File(nestedDir, "a.thrift")
|
||||
val fileAnotherAThrift = File(tempDir, "another_a.thrift")
|
||||
val fileBThrift = File(tempDir, "b.thrift")
|
||||
|
||||
fileNestedAThrift.writeText(
|
||||
"""
|
||||
namespace java com.microsoft.thrifty.test.crazyIncludeReferencedConst
|
||||
|
||||
const string HELLO = "hello"
|
||||
"""
|
||||
)
|
||||
fileAnotherAThrift.writeText(
|
||||
"""
|
||||
namespace java com.microsoft.thrifty.test.crazyIncludeReferencedConst
|
||||
|
||||
const string HELLO = "actually goodbye"
|
||||
"""
|
||||
)
|
||||
fileBThrift.writeText(
|
||||
"""
|
||||
include 'another_a.thrift'
|
||||
include 'nested/a.thrift'
|
||||
namespace java com.microsoft.thrifty.test.crazyIncludeReferencedConst
|
||||
|
||||
const string HELLO_AGAIN = a.HELLO
|
||||
"""
|
||||
)
|
||||
|
||||
val loader = Loader()
|
||||
loader.addIncludePath(tempDir.toPath())
|
||||
|
||||
val schema = loader.load()
|
||||
|
||||
val helloAgain = schema.constants.single { const -> const.name == "HELLO_AGAIN" }
|
||||
val referencedConstant = helloAgain.referencedConstants.single()
|
||||
referencedConstant.location.path shouldBe listOf("nested", "a.thrift").joinToString(File.separator)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun relativeIncludesConsiderIncludingFileLocation() {
|
||||
val thriftDir = File(tempDir, "thrift").apply { mkdir() }
|
||||
|
@ -1370,4 +1411,4 @@ class LoaderTest {
|
|||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче