Skip to content

C#: Make Nullable type a ConstructedType and VoidType a ValueType. #17621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions csharp/ql/lib/semmle/code/csharp/Generics.qll
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,17 @@ class ConstructedType extends ValueOrRefType, ConstructedGeneric {

override UnboundGenericType getUnboundGeneric() { constructed_generic(this, getTypeRef(result)) }

final override Type getChild(int n) { result = this.getTypeArgument(n) }
override Type getChild(int n) { result = this.getTypeArgument(n) }

final override string toStringWithTypes() {
override string toStringWithTypes() {
result = this.getUndecoratedName() + "<" + getTypeArgumentsToString(this) + ">"
}

final override string getName() {
override string getName() {
result = this.getUndecoratedName() + "<" + getTypeArgumentsNames(this) + ">"
}

final override predicate hasQualifiedName(string qualifier, string name) {
override predicate hasQualifiedName(string qualifier, string name) {
exists(string name0 | name = name0 + "<" + getTypeArgumentsQualifiedNames(this) + ">" |
exists(string enclosing |
this.getDeclaringType().hasQualifiedName(qualifier, enclosing) and
Expand Down
24 changes: 12 additions & 12 deletions csharp/ql/lib/semmle/code/csharp/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,20 @@ class NonNestedType extends ValueOrRefType {
NonNestedType() { exists(Namespace n | parent_namespace(this, n)) }
}

/**
* A value type.
*
* Either a simple type (`SimpleType`), an `enum` (`Enum`), a `struct` (`Struct`),
* or a nullable type (`NullableType`).
*/
class ValueType extends ValueOrRefType, @value_type {
override predicate isValueType() { any() }
}

/**
* The `void` type.
*/
class VoidType extends DotNet::ValueOrRefType, Type, @void_type {
class VoidType extends ValueType, Type, @void_type {
override predicate hasQualifiedName(string qualifier, string name) {
qualifier = "System" and
name = "Void"
Expand All @@ -419,16 +429,6 @@ class VoidType extends DotNet::ValueOrRefType, Type, @void_type {
override string getAPrimaryQlClass() { result = "VoidType" }
}

/**
* A value type.
*
* Either a simple type (`SimpleType`), an `enum` (`Enum`), a `struct` (`Struct`),
* or a nullable type (`NullableType`).
*/
class ValueType extends ValueOrRefType, @value_type {
override predicate isValueType() { any() }
}

/**
* A simple type. Simple types in C# are predefined `struct` types.
* Here, however, they are not modeled as such, and we reserve the
Expand Down Expand Up @@ -989,7 +989,7 @@ class NullType extends RefType, @null_type {
/**
* A nullable type, for example `int?`.
*/
class NullableType extends ValueType, DotNet::ConstructedGeneric, @nullable_type {
class NullableType extends ValueType, ConstructedType, @nullable_type {
/**
* Gets the underlying value type of this nullable type.
* For example `int` in `int?`.
Expand Down
4 changes: 2 additions & 2 deletions csharp/ql/lib/semmlecode.csharp.dbscheme
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ case @type.kind of
@unsigned_integral_type = @byte_type | @ushort_type | @uint_type | @ulong_type;
@floating_point_type = @float_type | @double_type;
@value_type = @simple_type | @enum_type | @struct_type | @nullable_type | @int_ptr_type
| @uint_ptr_type | @tuple_type;
| @uint_ptr_type | @tuple_type | @void_type;
@ref_type = @class_type | @interface_type | @array_type | @delegate_type | @null_type
| @dynamic_type;
@value_or_ref_type = @value_type | @ref_type;
Expand Down Expand Up @@ -2037,7 +2037,7 @@ cil_attribute_positional_argument(
@dotnet_type = @type | @cil_type;
@dotnet_call = @call | @cil_call_any;
@dotnet_throw = @throw_element | @cil_throw_any;
@dotnet_valueorreftype = @cil_valueorreftype | @value_or_ref_type | @cil_array_type | @void_type;
@dotnet_valueorreftype = @cil_valueorreftype | @value_or_ref_type | @cil_array_type;
@dotnet_typeparameter = @type_parameter | @cil_typeparameter;
@dotnet_array_type = @array_type | @cil_array_type;
@dotnet_pointer_type = @pointer_type | @cil_pointer_type;
Expand Down
Loading