Wiki

root/cobra/trunk/Tests/150-mixins/100-mixin-basics.cobra

Revision 2626, 1.0 KB (checked in by Charles.Esterbrook, 6 months ago)

Fixed: Using a local variable in a method or property in a mix-in causes false compilation errors.
reported-by:callisto

  • Property svn:eol-style set to native
Line 
1mixin Values
2
3    get one as int
4        return 1
5       
6    def two as int
7        return 2
8
9    def sum as int
10        total = .one  # test using a local var
11        total += .two
12        return total
13
14    def moreLocalVarTesting
15        if true
16            a = 1  # test local var inside a compound statement
17            CobraCore.noOp(a)
18        while false
19            b = 1
20            CobraCore.noOp(b)
21        if false
22            using tr = File.openText('foo')
23                pass
24       
25
26mixin Named
27
28    var _name as String?
29   
30    pro name as String
31        get
32            return _name ? ''
33        set
34            _name = value
35
36
37class A adds Named
38
39    pass
40
41
42
43class B adds Values
44
45    pass
46
47
48class C adds Named, Values
49
50    pass
51
52
53class P
54
55    def main is shared
56        a = A()
57        assert a inherits Named  # .no-warnings.
58        assert a.name == ''
59        a.name = 'a'
60        assert a.name == 'a'
61
62        b = B()
63        assert b inherits Values  # .no-warnings.
64        assert b.one == 1
65        assert b.two == 2
66
67        c = C()
68        assert c inherits Named  # .no-warnings.
69        assert c inherits Values  # .no-warnings.
70        assert c.one == 1
71        assert c.two == 2
72        assert c.name == ''
73        c.name = 'foo'
74        assert c.name == 'foo'
Note: See TracBrowser for help on using the browser.