Last change
on this file since 52eb7b7 was 4d5c5b6a, checked in by Peter A. Buhr <pabuhr@…>, 7 months ago |
add overload table data for Ada
|
-
Property mode
set to
100644
|
File size:
1000 bytes
|
Rev | Line | |
---|
[4d5c5b6a] | 1 | // overloading on return type
|
---|
| 2 | func random() -> Int{ 3; }
|
---|
| 3 | func random() -> String{ "abc"; }
|
---|
| 4 | func random() -> Double{ 3.5; }
|
---|
| 5 | var r1 : Int = random();
|
---|
| 6 | print( r1 );
|
---|
| 7 | var r2 : String = random();
|
---|
| 8 | print( r2 );
|
---|
| 9 | var r3 : Double = random();
|
---|
| 10 | print( r3 );
|
---|
| 11 |
|
---|
| 12 | // overloading functions without parameter names
|
---|
| 13 | func fun( _ x : Int ) -> Int{ 3; }
|
---|
| 14 | func fun( _ x : Int, _ y : Int ) -> Int{ x + y; }
|
---|
| 15 | func fun( _ x : String ) -> String{ "abc"; }
|
---|
| 16 | print( fun( 3, 4 ) );
|
---|
| 17 | // print( fun( 3.5 ) ); // no Double -> Int
|
---|
| 18 | //print( fun( r3 ) ); // no, Double -> Int
|
---|
| 19 |
|
---|
| 20 | // overloading on parameter name
|
---|
| 21 | func foo( x : Int ) -> Int{ 3; }
|
---|
| 22 | func foo( y : Int ) -> Int{ 3; }
|
---|
| 23 | print( foo( x : 3 ) );
|
---|
| 24 | print( foo( y : 3 ) );
|
---|
| 25 |
|
---|
| 26 | // overloading on generics
|
---|
| 27 | func bar<T>( _ a : T ) { print( "bar1", a ); }
|
---|
| 28 | func bar<T>( _ a : T, _ b : T ) { print( "bar2", a, b ); }
|
---|
| 29 | func bar<T,U>( _ a : T, _ b : U) { print( "bar3", a, b ); }
|
---|
| 30 | bar( 3 );
|
---|
| 31 | bar( 3.5 );
|
---|
| 32 | bar( 2, 2 );
|
---|
| 33 | bar( 2, 2.5 );
|
---|
| 34 |
|
---|
| 35 | // Local Variables: //
|
---|
| 36 | // compile-command: "swift test.swift" //
|
---|
| 37 | // End: //
|
---|
Note:
See
TracBrowser
for help on using the repository browser.