Wiki

root/cobra/trunk/Tests/240-generics/400-generic-methods/130-generic-method-constraints.cobra

Revision 1817, 0.5 KB (checked in by Chuck.Esterbrook, 3 years ago)

Fix test case to invoke the intended generic method.
reported-by:gauthier

  • Property svn:eol-style set to native
Line 
1class Util
2
3    shared
4
5        def swap<of T>(left as inout T, right as inout T)
6            tmp as T = left
7            left = right
8            right = tmp
9
10        def swapIfGreater<of T>(left as inout T, right as inout T)
11            where T must be IComparable<of T>  # test constraint
12            if left.compareTo(right) > 0
13                tmp as T = left
14                left = right
15                right = tmp
16
17
18class Test
19
20    def main is shared
21        a = 1
22        b = 2
23        Util.swap<of int>(inout a, inout b)
24        assert a == 2 and b == 1
25
26        # test constraint
27        assert a > b
28        Util.swapIfGreater<of int>(inout a, inout b)
29        assert a < b
Note: See TracBrowser for help on using the browser.