Repository: Microsoft/thrifty (kotlin)

Issue:
Const definitions referencing imported consts cannot be loaded
I have the following two thrift files:
___
`path/to/errors.thrift`
```thrift

const string ERROR_NOT_FOUND = "ErrorNotFound"
...
```
___
`service.thrift`
```thrift
include "path/to/errors.thrift"

const string NOT_FOUND = errors.ERROR_NOT_FOUND
...
```
___
While with Apache Thrift Compiler, I can generate code out of these two thrift files without issues, Thrifty failed to load `service.thrift` with the following error message:
```
E: Unrecognised const identifier: errors.ERROR_NOT_FOUND (at path/to/service.thrift)
```

Right now my workaround is to define `NOT_FOUDN` in `service.thrift` with literal `"ErrorNotFound"` instead of the imported reference `errors.ERROR_NOT_FOUND`.

Pull request description:
Fixes microsoft/thrifty#550

Patch:
diff --git a/thrifty-schema/src/main/kotlin/com/microsoft/thrifty/schema/Linker.kt b/thrifty-schema/src/main/kotlin/com/microsoft/thrifty/schema/Linker.kt
index 89e9e3de6..71c696bb6 100644
--- a/thrifty-schema/src/main/kotlin/com/microsoft/thrifty/schema/Linker.kt
+++ b/thrifty-schema/src/main/kotlin/com/microsoft/thrifty/schema/Linker.kt
@@ -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()
             }


Test patch:
diff --git a/thrifty-schema/src/test/kotlin/com/microsoft/thrifty/schema/LoaderTest.kt b/thrifty-schema/src/test/kotlin/com/microsoft/thrifty/schema/LoaderTest.kt
index 227af13e7..871294e93 100644
--- a/thrifty-schema/src/test/kotlin/com/microsoft/thrifty/schema/LoaderTest.kt
+++ b/thrifty-schema/src/test/kotlin/com/microsoft/thrifty/schema/LoaderTest.kt
@@ -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
             }
         }
-}
\ No newline at end of file
+}