Merge pull request #4627 from tamasvajk/feature/csharp9-covariant-return

C#: Add test for covariant return types
This commit is contained in:
Tamás Vajk
2021-03-03 16:12:13 +01:00
committed by GitHub
4 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
class A
{
public virtual A M1() { throw null; }
}
class B : A
{
public override B M1() { throw null; }
}

View File

@@ -117,6 +117,21 @@ BinaryPattern.cs:
# 19| 1: [SwitchCaseExpr] ... => ...
# 19| 0: [DiscardPatternExpr] _
# 19| 2: [StringLiteral] "other"
CovariantReturn.cs:
# 1| [Class] A
# 3| 5: [Method] M1
# 3| -1: [TypeMention] A
# 3| 4: [BlockStmt] {...}
# 3| 0: [ThrowStmt] throw ...;
# 3| 0: [NullLiteral] null
# 6| [Class] B
#-----| 3: (Base types)
# 6| 0: [TypeMention] A
# 8| 5: [Method] M1
# 8| -1: [TypeMention] B
# 8| 4: [BlockStmt] {...}
# 8| 0: [ThrowStmt] throw ...;
# 8| 0: [NullLiteral] null
Discard.cs:
# 3| [Class] Discard
# 5| 5: [Method] M1

View File

@@ -0,0 +1 @@
| A.M1 | A | B.M1 | B |

View File

@@ -0,0 +1,8 @@
import csharp
from Method m, Method overrider
where
m.getAnOverrider() = overrider and
m.getFile().getStem() = "CovariantReturn"
select m.getQualifiedName(), m.getReturnType().toString(), overrider.getQualifiedName(),
overrider.getReturnType().toString()