Fix attaching generic annotations (#9234)

Fixes the issue with attaching generic annotations in complex types.

Annotations in the type body could be lost during the compilation if its constructor was defined at the end of the type definition.
This commit is contained in:
Dmitry Bushev 2024-03-01 18:01:50 +00:00 committed by GitHub
parent 44a1d9138b
commit fad1b45bcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -26,7 +26,7 @@ import org.enso.compiler.pass.analyse.{
TailCall
}
import org.enso.compiler.pass.lint.UnusedBindings
import org.enso.compiler.pass.optimise.{LambdaConsolidate}
import org.enso.compiler.pass.optimise.LambdaConsolidate
import org.enso.compiler.pass.resolve.{
DocumentationComments,
IgnoredBindings,
@ -125,6 +125,7 @@ case object ComplexType extends IRPass {
lastAnnotations = Seq()
res
case _ =>
lastAnnotations = Seq()
None
}
// TODO[MK] this is probably removable

View File

@ -86,6 +86,28 @@ class ComplexTypeTest extends CompilerTest {
tp.members(1).name.name shouldEqual "Bar"
}
"have their annotations correct" in {
val ir =
"""
|type MyType
| @a 42
| bar self = self
|
| Foo
|""".stripMargin.preprocessModule.desugar
ir.bindings.length shouldEqual 3
val tp = ir.bindings(0).asInstanceOf[Definition.Type]
tp.name.name shouldEqual "MyType"
tp.members(0).name.name shouldEqual "Foo"
val a = ir.bindings(1).asInstanceOf[Name.GenericAnnotation]
a.name shouldEqual "a"
val bar = ir.bindings(2).asInstanceOf[definition.Method.Binding]
bar.methodName.name shouldEqual "bar"
}
"have their methods desugared to binding methods" in {
ir.bindings(3) shouldBe an[definition.Method.Binding]
val isJust = ir.bindings(3).asInstanceOf[definition.Method.Binding]