Commit 6ad812a5 by Tianqi Yang

test(overload): add negative tests for overload

Add test cases: - overload_error1: Overload errors - override_error1: Override overloaded functions errors - redef_error1: Redefinition errors
parent fdb42310
class A
{
void print ()
{
Print ( "A.print\n" );
}
}
class B extends A
{
void print ()
{
Print ( "B.print\n" );
}
}
class F
{
static void f ( class A a, class A b )
{
Print ( "F: A A\n" );
a.print ();
b.print ();
}
}
class G
{
static void f ( class A a, class A b )
{
Print ( "G: A A\n" );
}
static void f ( class A a, class B b )
{
Print ( "G: A B\n" );
}
static void f ( class B a, class A b )
{
Print ( "G: B A\n" );
}
static void f ( string s )
{
Print ( "G: string\n" );
}
}
class Main
{
static void main ()
{
class A a;
a = new A ();
class B b;
b = new B ();
F.f ( a, a );
F.f ( a, b );
F.f ( b, a );
F.f ( b, b );
F.f ( 1 );
G.f ( a, a );
G.f ( a, b );
G.f ( b, a );
G.f ( b, b );
G.f ( 1 );
}
}
\ No newline at end of file
class A
{
void print ()
{
Print ( "A.print\n" );
}
}
class B extends A
{
void print ()
{
Print ( "B.print\n" );
}
}
class F
{
void f ( class A a )
{
}
void f ( class B b )
{
}
int g;
string h;
}
class G extends F
{
int f;
void g ( class A a )
{
}
void g ( class B b )
{
}
bool h;
}
class Main
{
static void main ()
{
}
}
\ No newline at end of file
class A
{
void print ()
{
Print ( "A.print\n" );
}
}
class B extends A
{
void print ()
{
Print ( "B.print\n" );
}
}
class F
{
void f ( class A a )
{
}
int f ( class A c )
{
}
class A f ( class A abc )
{
}
void f ( class A b )
{
}
int g;
string h;
}
class Main
{
static int main ( int a, int b )
{
}
static void main ()
{
}
static int main ( int c, int d )
{
}
static int main ()
{
}
static void main ( int a )
{
}
}
\ No newline at end of file
*** Error at (63,5): function 'f' expects 2 argument(s) but 1 given
*** Error at (68,5): call of overloaded f(class : B, class : B) is ambiguous, candidates are :
*** note : candidate at (34,14) : void f(class : A, class : B)
*** note : candidate at (39,14) : void f(class : B, class : A)
*** Error at (69,5): no match function for call to f(int), candidates are :
*** note : candidate at (29,14) : void f(class : A, class : A)
error : function 'f' expects 2 argument(s) but 1 given
*** note : candidate at (34,14) : void f(class : A, class : B)
error : function 'f' expects 2 argument(s) but 1 given
*** note : candidate at (39,14) : void f(class : B, class : A)
error : function 'f' expects 2 argument(s) but 1 given
*** note : candidate at (44,14) : void f(string)
error : incompatible argument 1: int given, string expected
*** Error at (36,6): declaration of 'f' here conflicts with earlier declarations :
*** note : previously declared at (19,7) : void f(class : A)
*** note : previously declared at (24,7) : void f(class : B)
*** Error at (38,7): declaration of 'g' here conflicts with earlier declaration at (29,6)
*** Error at (43,7): declaration of 'g' here conflicts with earlier declaration at (29,6)
*** Error at (48,7): overriding variable is not allowed for var 'h'
*** Error at (24,6): ambiguous new declaration of 'int f(class : A)' :
*** note : previous declaration at (19,7) : void f(class : A)
*** Error at (29,10): ambiguous new declaration of 'class : A f(class : A)' :
*** note : previous declaration at (19,7) : void f(class : A)
*** Error at (34,7): redefinition of 'void f(class : A)' :
*** note : previous declaration at (19,7) : void f(class : A)
*** Error at (51,14): conflicting declaration of main function 'void main()' :
*** note : previous declaration at (46,13) : int main(int, int)
*** Error at (55,13): redefinition of 'int main(int, int)' :
*** note : previous declaration at (46,13) : int main(int, int)
*** Error at (60,13): ambiguous new declaration of 'int main()' :
*** note : previous declaration at (51,14) : void main()
*** Error at (65,14): conflicting declaration of main function 'void main(int)' :
*** note : previous declaration at (46,13) : int main(int, int)
*** note : previous declaration at (51,14) : void main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment