Skip to content

Commit f3885a8

Browse files
authored
Merge pull request #4627 from tamasvajk/feature/csharp9-covariant-return
C#: Add test for covariant return types
2 parents 3400c12 + a5a4329 commit f3885a8

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class A
2+
{
3+
public virtual A M1() { throw null; }
4+
}
5+
6+
class B : A
7+
{
8+
public override B M1() { throw null; }
9+
}

csharp/ql/test/library-tests/csharp9/PrintAst.expected

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ BinaryPattern.cs:
117117
# 19| 1: [SwitchCaseExpr] ... => ...
118118
# 19| 0: [DiscardPatternExpr] _
119119
# 19| 2: [StringLiteral] "other"
120+
CovariantReturn.cs:
121+
# 1| [Class] A
122+
# 3| 5: [Method] M1
123+
# 3| -1: [TypeMention] A
124+
# 3| 4: [BlockStmt] {...}
125+
# 3| 0: [ThrowStmt] throw ...;
126+
# 3| 0: [NullLiteral] null
127+
# 6| [Class] B
128+
#-----| 3: (Base types)
129+
# 6| 0: [TypeMention] A
130+
# 8| 5: [Method] M1
131+
# 8| -1: [TypeMention] B
132+
# 8| 4: [BlockStmt] {...}
133+
# 8| 0: [ThrowStmt] throw ...;
134+
# 8| 0: [NullLiteral] null
120135
Discard.cs:
121136
# 3| [Class] Discard
122137
# 5| 5: [Method] M1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| A.M1 | A | B.M1 | B |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import csharp
2+
3+
from Method m, Method overrider
4+
where
5+
m.getAnOverrider() = overrider and
6+
m.getFile().getStem() = "CovariantReturn"
7+
select m.getQualifiedName(), m.getReturnType().toString(), overrider.getQualifiedName(),
8+
overrider.getReturnType().toString()

0 commit comments

Comments
 (0)