File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 886c2ee93e53ba0082fe16ca9c5c15f07d7f5982
2
+ refs/heads/master: 93d425e7a5273a30846695b06b3de20ad406ed58
Original file line number Diff line number Diff line change
1
+ use std;
2
+
3
+ fn main ( ) {
4
+
5
+ // Anonymous object that doesn't extend an existing one.
6
+ let my_obj = obj ( ) {
7
+ fn foo ( ) -> int { ret 2 ; }
8
+ fn bar ( ) -> int { ret 3 ; }
9
+ fn baz ( ) -> str { "hello!" }
10
+ } ;
11
+
12
+ assert my_obj. foo ( ) == 2 ;
13
+ assert my_obj. bar ( ) == 3 ;
14
+ assert my_obj. baz ( ) == "hello!" ;
15
+
16
+ // Make sure the result is extendable.
17
+ let my_ext_obj = obj ( ) {
18
+ fn foo ( ) -> int { ret 3 ; }
19
+ fn quux ( ) -> str { ret self . baz ( ) ; }
20
+ with my_obj
21
+ } ;
22
+
23
+ assert my_ext_obj. foo ( ) == 3 ;
24
+ assert my_ext_obj. bar ( ) == 3 ;
25
+ assert my_ext_obj. baz ( ) == "hello!" ;
26
+ assert my_ext_obj. quux ( ) == "hello!" ;
27
+
28
+ // And again.
29
+ let my_ext_ext_obj = obj ( ) {
30
+ fn baz ( ) -> str { "world!" }
31
+ with my_ext_obj
32
+ } ;
33
+
34
+ assert my_ext_ext_obj. foo ( ) == 3 ;
35
+ assert my_ext_ext_obj. bar ( ) == 3 ;
36
+ assert my_ext_ext_obj. baz ( ) == "world!" ;
37
+ assert my_ext_ext_obj. quux ( ) == "world!" ;
38
+ }
You can’t perform that action at this time.
0 commit comments