-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathflow.rs
More file actions
3765 lines (3068 loc) · 89 KB
/
Copy pathflow.rs
File metadata and controls
3765 lines (3068 loc) · 89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#[cfg(test)]
mod test {
use crate::{DiagnosticCode, LuaType, VirtualWorkspace};
use emmylua_parser::{LuaAstToken, LuaLocalName};
use ntest::timeout;
const STACKED_TYPE_GUARDS: usize = 180;
const LARGE_LINEAR_ASSIGNMENT_STEPS: usize = 2048;
const MAXWELLHOME_ARRAY_VALUES: usize = 2048;
const ISSUE_1100_HIGHLIGHT_GROUPS: usize = 2048;
const ISSUE_1114_REPEATED_ASSIGNMENT_STEPS: usize = 512;
#[test]
fn test_closure_return() {
let mut ws = VirtualWorkspace::new_with_init_std_lib();
ws.def(
r#"
--- @generic T, U
--- @param arr T[]
--- @param op fun(item: T, index: integer): U
--- @return U[]
function map(arr, op)
end
"#,
);
let ty = ws.expr_ty(
r#"
map({ 1, 2, 3 }, function(item, i)
return tostring(item)
end)
"#,
);
let expected = ws.ty("string[]");
assert_eq!(ty, expected);
}
#[test]
fn test_issue_140_1() {
let mut ws = VirtualWorkspace::new_with_init_std_lib();
ws.def(
r#"
---@class Object
---@class T
local inject2class ---@type (Object| T)?
if jsonClass then
if inject2class then
A = inject2class
end
end
"#,
);
let ty = ws.expr_ty("A");
let type_desc = ws.humanize_type(ty);
assert_eq!(type_desc, "T");
}
#[test]
fn test_issue_140_2() {
let mut ws = VirtualWorkspace::new();
assert!(ws.has_no_diagnostic(
DiagnosticCode::NeedCheckNil,
r#"
local msgBody ---@type { _hgQuiteMsg : 1 }?
if not msgBody or not msgBody._hgQuiteMsg then
end
"#
));
}
#[test]
fn test_issue_140_3() {
let mut ws = VirtualWorkspace::new();
assert!(ws.has_no_diagnostic(
DiagnosticCode::NeedCheckNil,
r#"
local SELF ---@type unknown
if SELF ~= nil then
SELF:OnDestroy()
end
"#
));
}
#[test]
fn test_issue_107() {
let mut ws = VirtualWorkspace::new();
assert!(ws.has_no_diagnostic(
DiagnosticCode::NeedCheckNil,
r#"
---@type {bar?: fun():string}
local props
if props.bar then
local foo = props.bar()
end
if type(props.bar) == 'function' then
local foo = props.bar()
end
local foo = props.bar and props.bar() or nil
"#
));
}
#[test]
fn test_stacked_same_var_type_guards_build_semantic_model() {
let mut ws = VirtualWorkspace::new();
let repeated_guards =
"if type(value) ~= 'string' then return end\n".repeat(STACKED_TYPE_GUARDS);
let block = format!(
r#"
local value ---@type string|integer|boolean
{repeated_guards}
local narrowed ---@type string
narrowed = value
"#,
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked same-variable type guard repro"
);
assert!(ws.has_no_diagnostic(DiagnosticCode::AssignTypeMismatch, &block));
}
#[test]
fn test_stacked_same_var_truthiness_guards_build_semantic_model() {
let mut ws = VirtualWorkspace::new();
let repeated_guards = "if not value then return end\n".repeat(STACKED_TYPE_GUARDS);
let block = format!(
r#"
local value ---@type string?
{repeated_guards}
after_guard = value
"#,
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked same-variable truthiness repro"
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("string"));
}
#[test]
fn test_stacked_same_var_call_type_guards_build_semantic_model() {
let mut ws = VirtualWorkspace::new();
let repeated_guards =
"if not instance_of(value, 'string') then return end\n".repeat(STACKED_TYPE_GUARDS);
let block = format!(
r#"
---@generic T
---@param inst any
---@param type `T`
---@return TypeGuard<T>
local function instance_of(inst, type)
return true
end
local value ---@type string|integer|boolean
{repeated_guards}
after_guard = value
"#,
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked same-variable call type guard repro"
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("string"));
}
#[test]
fn test_stacked_local_call_alias_type_guards_build_semantic_model() {
let mut ws = VirtualWorkspace::new();
let repeated_guards = "if not pred(value) then return end\n".repeat(STACKED_TYPE_GUARDS);
let block = format!(
r#"
---@param v any
---@return TypeGuard<string>
local function is_string(v)
return true
end
local pred = is_string
local value ---@type string|integer|boolean
{repeated_guards}
after_guard = value
"#,
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked local call alias type guard repro"
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("string"));
}
#[test]
fn test_stacked_same_var_call_type_guard_eq_false_build_semantic_model() {
let mut ws = VirtualWorkspace::new();
let repeated_guards = "if instance_of(value, 'string') == false then return end\n"
.repeat(STACKED_TYPE_GUARDS);
let block = format!(
r#"
---@generic T
---@param inst any
---@param type `T`
---@return TypeGuard<T>
local function instance_of(inst, type)
return true
end
local value ---@type string|integer|boolean
{repeated_guards}
after_guard = value
"#,
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked binary call type guard repro"
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("string"));
}
#[test]
fn test_flow_assigned_call_type_guard_prefix_keeps_narrowing() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@generic T
---@param inst any
---@param type `T`
---@return TypeGuard<T>
local function instance_of(inst, type)
return true
end
local guard
guard = instance_of
local value ---@type string|integer|boolean
if guard(value, "string") then
after_guard = value
end
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("string"));
}
#[test]
fn test_condition_narrowed_call_type_guard_prefix_keeps_narrowing() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@param guard (fun(v: any): TypeGuard<string>)?
---@param value string|integer|boolean
local function f(guard, value)
if guard and guard(value) then
after_guard = value
end
end
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("string"));
}
#[test]
fn test_branch_join_keeps_union_when_only_one_side_narrows() {
let mut ws = VirtualWorkspace::new();
let block = r#"
local cond ---@type boolean
local value ---@type string|integer
if cond then
if type(value) ~= 'string' then
return
end
end
after_join = value
"#;
let file_id = ws.def(block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for branch join merge-safety repro"
);
assert_eq!(ws.expr_ty("after_join"), ws.ty("string|integer"));
}
#[test]
fn test_stacked_same_field_truthiness_guards_build_semantic_model() {
let mut ws = VirtualWorkspace::new();
let repeated_guards = "if not value.foo then return end\n".repeat(STACKED_TYPE_GUARDS);
let block = format!(
r#"
---@class HasFoo
---@field foo string
---@class NoFoo
---@field bar integer
local value ---@type HasFoo|NoFoo
{repeated_guards}
after_guard = value
"#,
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked same-field truthiness repro"
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("HasFoo"));
}
#[test]
fn test_stacked_return_cast_guards_build_semantic_model() {
let mut ws = VirtualWorkspace::new();
let repeated_guards =
"if not is_player(creature) then return end\n".repeat(STACKED_TYPE_GUARDS);
let block = format!(
r#"
---@class Creature
---@class Player: Creature
---@class Monster: Creature
---@return boolean
---@return_cast creature Player else Monster
local function is_player(creature)
return true
end
local creature ---@type Creature
{repeated_guards}
after_guard = creature
"#,
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked return-cast repro"
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("Player"));
}
#[test]
fn test_stacked_return_cast_self_guards_build_semantic_model() {
let mut ws = VirtualWorkspace::new();
let repeated_guards =
"if not creature:is_player() then return end\n".repeat(STACKED_TYPE_GUARDS);
let block = format!(
r#"
---@class Creature
---@class Player: Creature
---@class Monster: Creature
local creature = {{}}
---@return boolean
---@return_cast self Player else Monster
function creature:is_player()
return true
end
{repeated_guards}
after_guard = creature
"#,
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for stacked self return-cast repro"
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("Player"));
}
#[test]
fn test_large_linear_assignment_file_builds_semantic_model() {
let mut ws = VirtualWorkspace::new();
let mut block = String::from(
r#"
local value ---@type integer
value = 1
"#,
);
for i in 0..LARGE_LINEAR_ASSIGNMENT_STEPS {
block.push_str(&format!("local alias_{i} = value\n"));
block.push_str(&format!("value = alias_{i}\n"));
}
block.push_str("after_assign = value\n");
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for large linear assignment stress case"
);
let after_assign = ws.expr_ty("after_assign");
assert_eq!(ws.humanize_type(after_assign), "integer");
}
#[test]
#[timeout(5000)]
fn test_issue_1114_repeated_self_dependent_assignments_build_semantic_model() {
let cases = [
(
"concat",
r#"local value = """#,
"value = value .. config.pic[idx][index]",
),
(
"add",
"local value = 0",
"value = value + config.pic[idx][index]",
),
(
"comparison",
"local value = true",
"value = value == config.pic[idx][index]",
),
];
for (name, init, assignment) in cases {
let mut ws = VirtualWorkspace::new();
let repeated_assignments =
format!("{assignment}\n").repeat(ISSUE_1114_REPEATED_ASSIGNMENT_STEPS);
let block = format!(
r#"
function f(idx, index)
{init}
{repeated_assignments}
return value
end
"#
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for repeated self-dependent {name} assignment"
);
}
}
#[test]
#[timeout(5000)]
fn test_issue_1094_self_call_fallback_stress() {
let mut ws = VirtualWorkspace::new();
let repeated_calls = (2..=30)
.map(|i| format!("if count == 0 then count = self:api{i}():api(code) end\n"))
.collect::<String>();
let block = format!(
r#"
function class(className, super)
end
local Test = class("Test")
function Test:api1(code, isBind)
local count = self:api():api(code)
{repeated_calls}
return count
end
"#
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for repeated self-call fallback stress repro"
);
}
#[test]
#[timeout(5000)]
fn test_issue_1100_repeated_table_field_index_reads_after_unrelated_conditions() {
let mut ws = VirtualWorkspace::new();
let repeated_groups = (0..ISSUE_1100_HIGHLIGHT_GROUPS)
.map(|i| {
format!(
"if enabled('group_{i}') then\n hi('Group{i}', {{ fg = p.base0E, bg = p.base01, attr = nil, sp = nil }})\nend\n"
)
})
.collect::<String>();
let block = format!(
r#"
---@type {{ base01: string, base0E: string }}
local palette = {{ base01 = "a", base0E = "b" }}
local function enabled(name)
return name ~= ""
end
local function hi(group, args)
end
local p = palette
{repeated_groups}
result = p.base0E
"#
);
let file_id = ws.def(&block);
assert!(
ws.analysis
.compilation
.get_semantic_model(file_id)
.is_some(),
"expected semantic model for repeated palette field reads"
);
assert_eq!(ws.expr_ty("result"), ws.ty("string"));
}
#[test]
fn test_issue_1028_maxwellhome_like_large_array_builds_semantic_model() {
let mut ws = VirtualWorkspace::new();
let mut block = String::from(
r#"
---@type integer
local tile = ({
layers = {
{
data = {
"#,
);
for i in 0..MAXWELLHOME_ARRAY_VALUES {
block.push_str(&format!(" {},\n", i % 3));
}
block.push_str(
r#"
},
},
},
}).layers[1].data[1024]
"#,
);
let file_id = ws.def_file("maxwellhome.lua", &block);
let semantic_model = ws
.analysis
.compilation
.get_semantic_model(file_id)
.expect("expected semantic model for maxwellhome-like large array stress case");
let local_name = ws.get_node::<LuaLocalName>(file_id);
let token = local_name.get_name_token().expect("name token must exist");
let info = semantic_model
.get_semantic_info(token.syntax().clone().into())
.expect("semantic info must exist");
assert_eq!(ws.humanize_type(info.typ), "integer");
}
#[test]
fn test_pending_replay_order_uses_type_guard_before_self_return_cast_lookup() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@class Player
---@class Monster
local checker = {}
---@return boolean
---@return_cast self Player else Monster
function checker:is_player()
return true
end
local branch ---@type boolean
local creature = branch and checker or false
if type(creature) ~= "table" then
return
end
if not creature:is_player() then
return
end
after_guard = creature
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("Player"));
}
#[test]
fn test_pending_replay_order_with_three_guards_before_self_lookup() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@class PlayerA
---@class MonsterA
---@class PlayerB
---@class MonsterB
local checker_a = {
kind = "checker_a",
}
---@return boolean
---@return_cast self PlayerA else MonsterA
function checker_a:is_player()
return true
end
local checker_b = {
kind = "checker_b",
}
---@return boolean
---@return_cast self PlayerB else MonsterB
function checker_b:is_player()
return true
end
local allow_false ---@type boolean
local choose_a ---@type boolean
local creature = allow_false and false or (choose_a and checker_a or checker_b)
if type(creature) ~= "table" then
return
end
if creature.kind ~= "checker_a" then
return
end
if creature:is_player() == false then
return
end
after_guard = creature
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("PlayerA"));
}
#[test]
fn test_return_cast_self_guard_uses_prior_narrowing_for_method_lookup() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@class Player
---@class Monster
local checker = {
kind = "checker",
}
---@return boolean
---@return_cast self Player else Monster
function checker:is_player()
return true
end
local monster = {
kind = "monster",
}
local branch ---@type boolean
local creature = branch and checker or monster
if creature.kind ~= "checker" then
return
end
if not creature:is_player() then
return
end
after_guard = creature
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("Player"));
}
#[test]
fn test_return_cast_self_guard_without_prior_method_lookup_narrowing_does_not_apply() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@class Player
---@class Monster
local checker = {
kind = "checker",
}
---@return boolean
---@return_cast self Player else Monster
function checker:is_player()
return true
end
local monster = {
kind = "monster",
}
local branch ---@type boolean
local creature = branch and checker or monster
before_guard = creature
if not creature:is_player() then
return
end
after_guard = creature
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.expr_ty("before_guard"));
}
#[test]
fn test_return_cast_self_guard_with_multiple_method_candidates_uses_prior_narrowing() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@class PlayerA
---@class MonsterA
---@class PlayerB
---@class MonsterB
local checker_a = {
kind = "checker_a",
}
---@return boolean
---@return_cast self PlayerA else MonsterA
function checker_a:is_player()
return true
end
local checker_b = {
kind = "checker_b",
}
---@return boolean
---@return_cast self PlayerB else MonsterB
function checker_b:is_player()
return true
end
local branch ---@type boolean
local creature = branch and checker_a or checker_b
if creature.kind ~= "checker_a" then
return
end
if not creature:is_player() then
return
end
after_guard = creature
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("PlayerA"));
}
#[test]
fn test_return_cast_self_guard_with_non_callable_member_uses_prior_narrowing() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@class Player
---@class Monster
local checker = {
kind = "checker",
}
---@return boolean
---@return_cast self Player else Monster
function checker:is_player()
return true
end
local monster = {
kind = "monster",
is_player = false,
}
local branch ---@type boolean
local creature = branch and checker or monster
if creature.kind ~= "checker" then
return
end
if not creature:is_player() then
return
end
after_guard = creature
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("Player"));
}
#[test]
fn test_return_cast_self_guard_eq_false_uses_prior_narrowing_for_method_lookup() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@class Player
---@class Monster
local checker = {
kind = "checker",
}
---@return boolean
---@return_cast self Player else Monster
function checker:is_player()
return true
end
local monster = {
kind = "monster",
is_player = false,
}
local branch ---@type boolean
local creature = branch and checker or monster
if creature.kind ~= "checker" then
return
end
if creature:is_player() == false then
return
end
after_guard = creature
"#,
);
assert_eq!(ws.expr_ty("after_guard"), ws.ty("Player"));
}
#[test]
fn test_issue_100() {
let mut ws = VirtualWorkspace::new_with_init_std_lib();
assert!(ws.has_no_diagnostic(
DiagnosticCode::NeedCheckNil,
r#"
local f = io.open('', 'wb')
if not f then
error("Could not open a file")
end
f:write('')
"#
));
}
#[test]
fn test_issue_93() {
let mut ws = VirtualWorkspace::new_with_init_std_lib();
assert!(ws.has_no_diagnostic(
DiagnosticCode::ParamTypeMismatch,
r#"
local text --- @type string[]?
if staged then
local text1 --- @type string[]?
text = text1
else
local text2 --- @type string[]?
text = text2
end
if not text then
return
end
--- @param _a string[]
local function foo(_a) end
foo(text)
"#
));
}
#[test]
fn test_null_function_field() {
let mut ws = VirtualWorkspace::new_with_init_std_lib();
assert!(ws.has_no_diagnostic(
DiagnosticCode::NeedCheckNil,
r#"
---@class A
---@field aaa? fun(a: string)
local c ---@type A
if c.aaa then
c.aaa("aaa")
end
"#
))
}