Mercurial > vim
comparison src/testdir/test_vim9_class.vim @ 31590:aee868b9229a v9.0.1127
patch 9.0.1127: no error if function argument shadows class member
Commit: https://github.com/vim/vim/commit/6acf757c6a11c0653b0132a17c22983856da5ad6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 1 19:53:30 2023 +0000
patch 9.0.1127: no error if function argument shadows class member
Problem: No error if function argument shadows class member.
Solution: Give an error for shadowing a class member.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Jan 2023 21:00:03 +0100 |
parents | 8bbc932fbd09 |
children | 9b13b3a63bc0 |
comparison
equal
deleted
inserted
replaced
31589:55ea4210d8c6 | 31590:aee868b9229a |
---|---|
365 var c = MyCar.new("def") | 365 var c = MyCar.new("def") |
366 END | 366 END |
367 v9.CheckScriptFailure(lines, 'E1041:') | 367 v9.CheckScriptFailure(lines, 'E1041:') |
368 enddef | 368 enddef |
369 | 369 |
370 def Test_class_member_access() | 370 def Test_class_member() |
371 # check access rules | |
371 var lines =<< trim END | 372 var lines =<< trim END |
372 vim9script | 373 vim9script |
373 class TextPos | 374 class TextPos |
374 this.lnum = 1 | 375 this.lnum = 1 |
375 this.col = 1 | 376 this.col = 1 |
399 assert_equal(12, TextPos.anybody) | 400 assert_equal(12, TextPos.anybody) |
400 TextPos.anybody += 5 | 401 TextPos.anybody += 5 |
401 assert_equal(17, TextPos.anybody) | 402 assert_equal(17, TextPos.anybody) |
402 END | 403 END |
403 v9.CheckScriptSuccess(lines) | 404 v9.CheckScriptSuccess(lines) |
405 | |
406 # check shadowing | |
407 lines =<< trim END | |
408 vim9script | |
409 | |
410 class Some | |
411 static count = 0 | |
412 def Method(count: number) | |
413 echo count | |
414 enddef | |
415 endclass | |
416 | |
417 var s = Some.new() | |
418 s.Method(7) | |
419 END | |
420 v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: count') | |
421 | |
422 lines =<< trim END | |
423 vim9script | |
424 | |
425 class Some | |
426 static count = 0 | |
427 def Method(arg: number) | |
428 var count = 3 | |
429 echo arg count | |
430 enddef | |
431 endclass | |
432 | |
433 var s = Some.new() | |
434 s.Method(7) | |
435 END | |
436 v9.CheckScriptFailure(lines, 'E1341: Variable already declared in the class: count') | |
404 enddef | 437 enddef |
405 | 438 |
406 def Test_class_function() | 439 def Test_class_function() |
407 var lines =<< trim END | 440 var lines =<< trim END |
408 vim9script | 441 vim9script |