From a5a432966949ad32a3edfe75ecbace091b04633a Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Fri, 6 Nov 2020 10:37:38 +0100 Subject: [PATCH] C#: Add tests for covariant return types --- .../test/library-tests/csharp9/CovariantReturn.cs | 9 +++++++++ .../test/library-tests/csharp9/PrintAst.expected | 15 +++++++++++++++ .../csharp9/covariantReturn.expected | 1 + .../test/library-tests/csharp9/covariantReturn.ql | 8 ++++++++ 4 files changed, 33 insertions(+) create mode 100644 csharp/ql/test/library-tests/csharp9/CovariantReturn.cs create mode 100644 csharp/ql/test/library-tests/csharp9/covariantReturn.expected create mode 100644 csharp/ql/test/library-tests/csharp9/covariantReturn.ql diff --git a/csharp/ql/test/library-tests/csharp9/CovariantReturn.cs b/csharp/ql/test/library-tests/csharp9/CovariantReturn.cs new file mode 100644 index 00000000000..ac39aae893d --- /dev/null +++ b/csharp/ql/test/library-tests/csharp9/CovariantReturn.cs @@ -0,0 +1,9 @@ +class A +{ + public virtual A M1() { throw null; } +} + +class B : A +{ + public override B M1() { throw null; } +} \ No newline at end of file diff --git a/csharp/ql/test/library-tests/csharp9/PrintAst.expected b/csharp/ql/test/library-tests/csharp9/PrintAst.expected index 56299fbdc68..6da09ceb287 100644 --- a/csharp/ql/test/library-tests/csharp9/PrintAst.expected +++ b/csharp/ql/test/library-tests/csharp9/PrintAst.expected @@ -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 diff --git a/csharp/ql/test/library-tests/csharp9/covariantReturn.expected b/csharp/ql/test/library-tests/csharp9/covariantReturn.expected new file mode 100644 index 00000000000..789c8c7caaa --- /dev/null +++ b/csharp/ql/test/library-tests/csharp9/covariantReturn.expected @@ -0,0 +1 @@ +| A.M1 | A | B.M1 | B | diff --git a/csharp/ql/test/library-tests/csharp9/covariantReturn.ql b/csharp/ql/test/library-tests/csharp9/covariantReturn.ql new file mode 100644 index 00000000000..f4958cbba31 --- /dev/null +++ b/csharp/ql/test/library-tests/csharp9/covariantReturn.ql @@ -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()