Mercurial > vim
comparison src/testdir/test_vim9_class.vim @ 33924:ccdb948c7273 v9.0.2160
patch 9.0.2160: instanceof() should use varargs as second arg
Commit: https://github.com/vim/vim/commit/2025af165ec68d831f0f0f668a3ceac3f39142ef
Author: Ernie Rael <errael@raelity.com>
Date: Tue Dec 12 16:58:00 2023 +0100
patch 9.0.2160: instanceof() should use varargs as second arg
Problem: instanceof() should use varargs as second arg
Solution: Modify `instanceof()` to use varargs instead of list
Modify `instanceof()` to use varargs instead of list
Valid `instanceof()` arguments are `type`s. A `type` is not a value;
it cannot be added to a list.
This change is non-compatible with the current usage of instanceof;
but instanceof is relatively new and it's a trivial change.
fixes: #13421
closes: #13644
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 12 Dec 2023 17:15:03 +0100 |
parents | a259471e74fe |
children | 34c5f47e98ba |
comparison
equal
deleted
inserted
replaced
33923:b1e48fed6e55 | 33924:ccdb948c7273 |
---|---|
3326 endclass | 3326 endclass |
3327 | 3327 |
3328 class Base3 extends Mix1 | 3328 class Base3 extends Mix1 |
3329 endclass | 3329 endclass |
3330 | 3330 |
3331 type AliasBase1 = Base1 | |
3332 type AliasBase2 = Base2 | |
3333 type AliasIntf1 = Intf1 | |
3334 type AliasMix1 = Mix1 | |
3335 | |
3331 var b1 = Base1.new() | 3336 var b1 = Base1.new() |
3332 var b2 = Base2.new() | 3337 var b2 = Base2.new() |
3333 var b3 = Base3.new() | 3338 var b3 = Base3.new() |
3334 | 3339 |
3335 assert_true(instanceof(b1, Base1)) | 3340 assert_true(instanceof(b1, Base1)) |
3336 assert_true(instanceof(b2, Base1)) | 3341 assert_true(instanceof(b2, Base1)) |
3337 assert_false(instanceof(b1, Base2)) | 3342 assert_false(instanceof(b1, Base2)) |
3338 assert_true(instanceof(b3, Mix1)) | 3343 assert_true(instanceof(b3, Mix1)) |
3339 assert_false(instanceof(b3, [])) | 3344 assert_true(instanceof(b3, Base1, Base2, Intf1)) |
3340 assert_true(instanceof(b3, [Base1, Base2, Intf1])) | 3345 |
3346 assert_true(instanceof(b1, AliasBase1)) | |
3347 assert_true(instanceof(b2, AliasBase1)) | |
3348 assert_false(instanceof(b1, AliasBase2)) | |
3349 assert_true(instanceof(b3, AliasMix1)) | |
3350 assert_true(instanceof(b3, AliasBase1, AliasBase2, AliasIntf1)) | |
3341 | 3351 |
3342 def Foo() | 3352 def Foo() |
3343 var a1 = Base1.new() | 3353 var a1 = Base1.new() |
3344 var a2 = Base2.new() | 3354 var a2 = Base2.new() |
3345 var a3 = Base3.new() | 3355 var a3 = Base3.new() |
3346 | 3356 |
3347 assert_true(instanceof(a1, Base1)) | 3357 assert_true(instanceof(a1, Base1)) |
3348 assert_true(instanceof(a2, Base1)) | 3358 assert_true(instanceof(a2, Base1)) |
3349 assert_false(instanceof(a1, Base2)) | 3359 assert_false(instanceof(a1, Base2)) |
3350 assert_true(instanceof(a3, Mix1)) | 3360 assert_true(instanceof(a3, Mix1)) |
3351 assert_false(instanceof(a3, [])) | 3361 assert_true(instanceof(a3, Base1, Base2, Intf1)) |
3352 assert_true(instanceof(a3, [Base1, Base2, Intf1])) | 3362 |
3363 assert_true(instanceof(a1, AliasBase1)) | |
3364 assert_true(instanceof(a2, AliasBase1)) | |
3365 assert_false(instanceof(a1, AliasBase2)) | |
3366 assert_true(instanceof(a3, AliasMix1)) | |
3367 assert_true(instanceof(a3, AliasBase1, AliasBase2, AliasIntf1)) | |
3353 enddef | 3368 enddef |
3354 Foo() | 3369 Foo() |
3355 | 3370 |
3356 var o_null: Base1 | 3371 var o_null: Base1 |
3357 assert_false(instanceof(o_null, Base1)) | 3372 assert_false(instanceof(o_null, Base1)) |
3358 | 3373 |
3359 END | 3374 END |
3360 v9.CheckSourceSuccess(lines) | 3375 v9.CheckSourceSuccess(lines) |
3376 | |
3377 lines =<< trim END | |
3378 vim9script | |
3379 | |
3380 class Base1 | |
3381 endclass | |
3382 instanceof(Base1.new()) | |
3383 END | |
3384 v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: instanceof') | |
3385 | |
3386 lines =<< trim END | |
3387 vim9script | |
3388 | |
3389 class Base1 | |
3390 endclass | |
3391 def F() | |
3392 instanceof(Base1.new()) | |
3393 enddef | |
3394 F() | |
3395 END | |
3396 v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: instanceof') | |
3397 | |
3398 lines =<< trim END | |
3399 vim9script | |
3400 | |
3401 class Base1 | |
3402 endclass | |
3403 | |
3404 class Base2 | |
3405 endclass | |
3406 | |
3407 var o = Base2.new() | |
3408 instanceof(o, Base1, Base2, 3) | |
3409 END | |
3410 v9.CheckSourceFailure(lines, 'E693: Class or class typealias required for argument 4', 10) | |
3411 | |
3412 lines =<< trim END | |
3413 vim9script | |
3414 | |
3415 class Base1 | |
3416 endclass | |
3417 | |
3418 class Base2 | |
3419 endclass | |
3420 | |
3421 def F() | |
3422 var o = Base2.new() | |
3423 instanceof(o, Base1, Base2, 3) | |
3424 enddef | |
3425 F() | |
3426 END | |
3427 v9.CheckSourceFailure(lines, 'E693: Class or class typealias required for argument 4') | |
3361 enddef | 3428 enddef |
3362 | 3429 |
3363 " Test for calling a method in the parent class that is extended partially. | 3430 " Test for calling a method in the parent class that is extended partially. |
3364 " This used to fail with the 'E118: Too many arguments for function: Text' error | 3431 " This used to fail with the 'E118: Too many arguments for function: Text' error |
3365 " message (Github issue #12524). | 3432 " message (Github issue #12524). |