This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More update for default interface methods (#10818)
* Support protected methods * add a test for diamond shape scenario and tentatively throw exception when that happens
- Loading branch information
Showing
7 changed files
with
445 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
tests/src/Loader/classloader/DefaultInterfaceMethods/diamondshape/diamondshape.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
|
||
interface IFoo | ||
{ | ||
int Foo(int a); | ||
} | ||
|
||
class IFoo_Impl | ||
{ | ||
int Foo(int a) | ||
{ | ||
return a; | ||
} | ||
} | ||
|
||
interface IFoo2 : IFoo | ||
{ | ||
} | ||
|
||
class IFoo2_Impl : IFoo | ||
{ | ||
int IFoo.Foo(int a) | ||
{ | ||
Console.WriteLine("At IFoo2.Foo"); | ||
return a + 1; | ||
} | ||
} | ||
|
||
interface IFooEx : IFoo | ||
{ | ||
} | ||
|
||
class IFooEx_Impl : IFoo | ||
{ | ||
int IFoo.Foo(int a) | ||
{ | ||
Console.WriteLine("At IFooEx.Foo"); | ||
return a + 2; | ||
} | ||
} | ||
|
||
class FooClass : IFoo2, IFooEx | ||
{ | ||
// Dummy | ||
public int Foo(int a) | ||
{ | ||
return 0; | ||
} | ||
} | ||
|
||
class Program | ||
{ | ||
public static int Main() | ||
{ | ||
FooClass fooObj = new FooClass(); | ||
IFoo foo = (IFoo) fooObj; | ||
|
||
Console.WriteLine("Calling IFoo.Foo on Foo - expecting exception."); | ||
try | ||
{ | ||
foo.Foo(10); | ||
Test.Assert(false, "Expecting exception"); | ||
} | ||
catch(Exception) | ||
{ | ||
} | ||
|
||
return Test.Ret(); | ||
} | ||
} | ||
|
||
class Test | ||
{ | ||
private static bool Pass = true; | ||
|
||
public static int Ret() | ||
{ | ||
return Pass? 100 : 101; | ||
} | ||
|
||
public static void Assert(bool cond, string msg) | ||
{ | ||
if (cond) | ||
{ | ||
Console.WriteLine("PASS"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("FAIL: " + msg); | ||
Pass = false; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.