Bugfix for passing default arguments to GSI calls

This happens when default arguments (specifically
user class or enum types) and passed between keyword
and positional arguments. We must not use a temporary
tl::Variant object as it gets out of scope and a
reference is stored.

In addition: better error messages for Python when
a method can't be matched to arguments.
This commit is contained in:
Matthias Koefferlein
2024-05-25 17:48:17 +02:00
parent 370abf7ab3
commit 1861abc68c
6 changed files with 139 additions and 15 deletions
+47
View File
@@ -3154,4 +3154,51 @@ class Basic_TestClass < TestBase
end
# keyword arguments, enums and error messages
def test_81
bb = RBA::BB::new
m = ""
begin
bb.d4()
rescue => ex
m = ex.to_s
end
assert_equal(m, "Can't match arguments. Variants are:\n string d4(int a, string b, double c, B3::E d = E3A, variant e = nil) [no value given for argument #1 and following]\n in BB.d4")
m = ""
begin
bb.d4(1, "a")
rescue => ex
m = ex.to_s
end
assert_equal(m, "Can't match arguments. Variants are:\n string d4(int a, string b, double c, B3::E d = E3A, variant e = nil) [no value given for argument #3]\n in BB.d4")
m = ""
begin
bb.d4(1, "a", 2.0, xxx=17)
rescue => ex
m = ex.to_s
end
assert_equal(m, "Unknown keyword parameter: xxx in BB.d4")
m = ""
begin
bb.d4(a=1, b="a", c=2.0, xxx=17)
rescue => ex
m = ex.to_s
end
assert_equal(m, "Unknown keyword parameter: xxx in BB.d4")
assert_equal(bb.d4(1, "a", 2.0), "1,a,2,100,nil")
assert_equal(bb.d4(1, "a", 2.0, e=42), "1,a,2,100,42")
assert_equal(bb.d4(1, "a", c=2.0, e=42), "1,a,2,100,42")
assert_equal(bb.d4(c=2.0, a=1, b="a", e=42), "1,a,2,100,42")
assert_equal(bb.d4(1, "a", 2.0, d=RBA::BB::E::E3B), "1,a,2,101,nil")
assert_equal(bb.d4(1, "a", d=RBA::BB::E::E3B, c=2.5), "1,a,2.5,101,nil")
assert_equal(bb.d4(1, "a", 2.0, RBA::BB::E::E3B, 42), "1,a,2,101,42")
end
end