From af2d6adad5d4c11de8ff0c1deb47ed01a87121cc Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Mon, 11 Mar 2024 15:53:05 +0900 Subject: [PATCH] Add simple interface call test --- cli/src/main/scala/TestSuites.scala | 1 + .../scala/testsuite/core/InterfaceCall.scala | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test-suite/src/main/scala/testsuite/core/InterfaceCall.scala diff --git a/cli/src/main/scala/TestSuites.scala b/cli/src/main/scala/TestSuites.scala index 2d5f7f35..702bd4cb 100644 --- a/cli/src/main/scala/TestSuites.scala +++ b/cli/src/main/scala/TestSuites.scala @@ -7,6 +7,7 @@ object TestSuites { TestSuite("testsuite.core.add.Add", "add"), TestSuite("testsuite.core.add.Add", "add"), TestSuite("testsuite.core.virtualdispatch.VirtualDispatch", "virtualDispatch"), + TestSuite("testsuite.core.interfacecall.InterfaceCall", "interfaceCall"), TestSuite("testsuite.core.asinstanceof.AsInstanceOfTest", "asInstanceOf"), TestSuite("testsuite.core.hijackedclassesmono.HijackedClassesMonoTest", "hijackedClassesMono") ) diff --git a/test-suite/src/main/scala/testsuite/core/InterfaceCall.scala b/test-suite/src/main/scala/testsuite/core/InterfaceCall.scala new file mode 100644 index 00000000..609ae970 --- /dev/null +++ b/test-suite/src/main/scala/testsuite/core/InterfaceCall.scala @@ -0,0 +1,31 @@ +package testsuite.core.interfacecall + +import scala.scalajs.js.annotation._ + +object InterfaceCall { + def main(): Unit = { val _ = test() } + + @JSExportTopLevel("interfaceCall") + def test(): Boolean = { + val c = new Concrete() + c.plus(c.zero, 1) == 1 && c.minus(1, c.zero) == 1 + } + + class Concrete extends AddSub with Zero { + override def zero: Int = 0 + } + + trait Adder { + def plus(a: Int, b: Int) = a + b + } + + trait Sub { + def minus(a: Int, b: Int): Int = a - b + } + + trait AddSub extends Adder with Sub + + trait Zero { + def zero: Int + } +}