Error in xvar?
This works and prints 2:
def test2(): Unit \ IO = {
ematch xvar Edge(2) {
case Edge(x) => println(x)
case Edge(_) => ???
}
}
This does not work. It types Edge((2, 3)) as XVar[#(Edge(Int32, Int32))].
def test1(): Unit \ IO = {
ematch xvar Edge((2, 3)) {
case Edge(x) => println(x)
case Edge(_) => ???
}
}
Error:
#
# An unexpected error has been detected by the Flix compiler:
#
# Bad type on operand stack
Exception Details:
Location:
Def$test1.directApply(Ldev/flix/runtime/Unit$;)Ldev/flix/runtime/Result$; @23: putfield
Reason:
Type 'Tuple$Int32$Int32' (current frame, stack[2]) is not assignable to integer
Current Frame:
bci: @23
flags: { }
locals: { 'dev/flix/runtime/Unit$' }
stack: { 'Tag$Int32$Int32', 'Tag$Int32$Int32', 'Tuple$Int32$Int32' }
Bytecode:
0000000: bb00 1659 b700 1759 1219 b500 1f59 bb00
0000010: 2159 0506 b700 24b5 0028 c000 1b4c 2bc0
0000020: 001b b400 1f12 19a5 0007 03a7 0004 049a
0000030: 0024 2bc0 001b 4ebb 002a 5912 2cbb 002e
0000040: 5912 3007 1019 0710 1cb7 0033 b700 36bf
0000050: 0000 bf2b c000 16b4 0028 3dbb 0038 59b7
0000060: 0039 592c b500 0eb0 0000 0000 0000 0000
0000070: bf00 0000 0000 0000 0000 0000 0000 bf
Stackmap Table:
append_frame(@46,Object[#27])
same_locals_1_stack_item_frame(@47,Integer)
full_frame(@80,{},{Object[#65]})
append_frame(@83,Object[#16],Object[#27])
full_frame(@104,{},{Object[#65]})
same_locals_1_stack_item_frame(@113,Object[#65])
#
# This is a bug in the Flix compiler. Please report it here:
#
# https://github.com/flix/flix/issues
#
# -- Flix Compiler --
#
# Flix Version : 0.59.0
# incremental: All
#
# -- Java Virtual Machine --
#
# JVM Version : 23.0.1 (2024-10-15)
# JVM Vendor : Oracle Corporation
# JAVA_HOME : C:\Users\caspe\.jdks\openjdk-23.0.1
# System : Windows 11 (10.0)
#
# -- Stack Trace --
java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
Def$test1.directApply(Ldev/flix/runtime/Unit$;)Ldev/flix/runtime/Result$; @23: putfield
Reason:
Type 'Tuple$Int32$Int32' (current frame, stack[2]) is not assignable to integer
Current Frame:
bci: @23
flags: { }
locals: { 'dev/flix/runtime/Unit$' }
stack: { 'Tag$Int32$Int32', 'Tag$Int32$Int32', 'Tuple$Int32$Int32' }
Bytecode:
0000000: bb00 1659 b700 1759 1219 b500 1f59 bb00
0000010: 2159 0506 b700 24b5 0028 c000 1b4c 2bc0
0000020: 001b b400 1f12 19a5 0007 03a7 0004 049a
0000030: 0024 2bc0 001b 4ebb 002a 5912 2cbb 002e
0000040: 5912 3007 1019 0710 1cb7 0033 b700 36bf
0000050: 0000 bf2b c000 16b4 0028 3dbb 0038 59b7
0000060: 0039 592c b500 0eb0 0000 0000 0000 0000
0000070: bf00 0000 0000 0000 0000 0000 0000 bf
Stackmap Table:
append_frame(@46,Object[#27])
same_locals_1_stack_item_frame(@47,Integer)
full_frame(@80,{},{Object[#65]})
append_frame(@83,Object[#16],Object[#27])
full_frame(@104,{},{Object[#65]})
same_locals_1_stack_item_frame(@113,Object[#65])
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3650)
at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3675)
at java.base/java.lang.Class.getMethods(Class.java:2244)
at ca.uwaterloo.flix.util.JvmUtils$.getMethods(JvmUtils.scala:92)
at ca.uwaterloo.flix.util.JvmUtils$.getMethods(JvmUtils.scala:64)
at ca.uwaterloo.flix.language.phase.jvm.JvmLoader$.methodsOf(JvmLoader.scala:150)
at ca.uwaterloo.flix.language.phase.jvm.JvmLoader$.$anonfun$load$1(JvmLoader.scala:102)
at scala.collection.IterableOnceOps.foldLeft(IterableOnce.scala:727)
at scala.collection.IterableOnceOps.foldLeft$(IterableOnce.scala:721)
at scala.collection.AbstractIterable.foldLeft(Iterable.scala:935)
at ca.uwaterloo.flix.language.phase.jvm.JvmLoader$.load(JvmLoader.scala:101)
at ca.uwaterloo.flix.language.phase.jvm.JvmLoader$.run(JvmLoader.scala:52)
at ca.uwaterloo.flix.api.Flix.codeGen(Flix.scala:692)
at ca.uwaterloo.flix.runtime.shell.Shell.compile(Shell.scala:374)
at ca.uwaterloo.flix.runtime.shell.Shell.run(Shell.scala:402)
at ca.uwaterloo.flix.runtime.shell.Shell.execEval(Shell.scala:320)
at ca.uwaterloo.flix.runtime.shell.Shell.execReloadAndEval(Shell.scala:336)
at ca.uwaterloo.flix.runtime.shell.Shell.execute(Shell.scala:167)
at ca.uwaterloo.flix.runtime.shell.Shell.loop(Shell.scala:115)
at ca.uwaterloo.flix.Main$.main(Main.scala:258)
at ca.uwaterloo.flix.Main.main(Main.scala)
Run with the newest newest master.
--Your second program is incorrect and will be rejected by the type system. We are just not done with all the checks.--
My bad. The second program should be OK.
@jaschdoc / @JonathanStarup is this simple a consequence of the frontend not being done yet?
I would have expected it to work for any single argument XVar-- even tuples.
Or maybe its because #10532 is not in yet?
Or maybe its because #10532 is not in yet?
Yes, this program is observing the unsoundness that arity will fix
Short explanation for @CasperDN, you can confuse the compiler when you try to use xvar with one term of a tuple type as you showed. So generally you should avoid that until the fix is merged in
@CasperDN It seems this is expected behavior until our fix is in-- which can happen next week.
I just wanted to check whether it was a known problem, coding around it is not hard. Should I just close the issue, or should it stay until the fix is in?
Keep it open in case we get distracted by something and don't fix it :P
We have now fixed the predicate arity thing. But we are still working on ext vars.
@jaschdoc Is this still relevant?
This works now.
def main(): Unit \ IO = {
ematch xvar Edge((1, 2)) {
case Edge(x) => println(x)
}
}