Debian Codegraph @

gcc/testsuite/gdc.test/compilable/test18199.d

raw
1 // https://issues.dlang.org/show_bug.cgi?id=18199
2
3 //
4 // struct initializer cases
5 //
6
7 // original error report
8 struct Bla
9 {
10 int delegate(int, int) fun;
11 }
12 Bla bla1 = Bla((int a, int b) { return a + b; });
13 Bla bla2 = {(int a, int b) { return a + b; }}; // yielded error
14
15 // additional error report with memberName:expression syntax
16 struct Foo
17 {
18 int function(int) bar;
19 int function(int) bar2;
20 }
21 Foo foo =
22 {
23 bar : function(x) { return 2 * x; }, // yielded error
24 bar2 : (x) => 2 * x,
25 };
26
27 struct MyStruct
28 {
29 int function() f;
30 int delegate() d;
31 }
32
33 // confirm that ambiguous cases assume struct initializer
34 MyStruct ambiguous_1 = {};
35 MyStruct ambiguous_2 =
36 {
37 { return 1 + 1; }
38 };
39
40 // statement-holding function literal variants not covered above
41 static MyStruct function_and_delegate_keywords =
42 {
43 function () { return 1 + 1; },
44 delegate () { return 1 + 1; }
45 };
46
47 //
48 // function literal initializer cases
49 //
50
51 alias IntFun = int function();
52 alias VoidFun = void function();
53
54 IntFun colon_at_top_level =
55 {
56 return 1 + 1;
57 };
58
59 IntFun block_statement_only_with_nested_statement =
60 {
61 if (true)
62 {
63 return 1 + 1;
64 }
65 };
66
67 struct SomeStruct {}
68
69 // previously these cases were incorrectly parsed as struct initializer
70 VoidFun[] no_semicolon_statements = [
71 { asm {} },
72 { class Foo {} },
73 { debug(foo) {} },
74 { enum Foo { A } },
75 { final switch(5) {} },
76 { if (true) {} },
77 { interface Foo {} },
78 { pragma(inline) {} },
79 { scope(exit) {} },
80 { struct Foo {} },
81 { synchronized {} },
82 { try {} finally {} },
83 { union Foo {} },
84 { version(foo) {} },
85 { while (false) {} },
86 { with (SomeStruct) {} },
87 ];