Skip to content

IsUserDefinedTypeWithEquals NullRefException #146

@jetdog8808

Description

@jetdog8808

Describe the bug in detail:
Trying to use .Remove on a UdonSharpBehaviour inherited class list, and get a compile error.

Provide steps/code to reproduce the bug:
Create a List of a UdonSharpBehaviour inherited class not overriding Equals method.
Then use .Remove, .Contains, or .IndexOf on that list.
Compile and error should pop up.

Expected behavior:
There should be no error.

Additional Information:

else if (symbol.Name == nameof(UdonSharpInternalUtility.IsUserDefinedTypeWithEquals))
{
// Return constant value based on if generic type is a user defined type with Equals
TypeSymbol typeArg = symbol.TypeArguments[0];
bool isUserDefinedTypeWithEquals = typeArg.IsUdonSharpBehaviour || typeArg is ImportedUdonSharpTypeSymbol;
if (isUserDefinedTypeWithEquals)
{
// Check if the type has an Equals method
IEnumerable<MethodSymbol> equalsMethods = typeArg.GetMembers<MethodSymbol>("Equals", context);
isUserDefinedTypeWithEquals = equalsMethods.Any(e => e.Parameters.Length == 1 &&
e.ReturnType == context.GetTypeSymbol(SpecialType.System_Boolean) &&
e.Parameters[0].Type == context.GetTypeSymbol(SpecialType.System_Object));
TypeSymbol objectType = context.GetTypeSymbol(SpecialType.System_Object);
if (typeArg.IsUdonSharpBehaviour)
{
while (!isUserDefinedTypeWithEquals && typeArg != null && typeArg.IsUdonSharpBehaviour)
{
if (typeArg.BaseType == objectType)
break;
equalsMethods = typeArg.BaseType.GetMembers<MethodSymbol>("Equals", context);
isUserDefinedTypeWithEquals = equalsMethods.Any(e => e.Parameters.Length == 1 &&
e.ReturnType == context.GetTypeSymbol(SpecialType.System_Boolean) &&
e.Parameters[0].Type == context.GetTypeSymbol(SpecialType.System_Object));
typeArg = typeArg.BaseType;
}
}
}
IConstantValue constantValue = new ConstantValue<bool>(isUserDefinedTypeWithEquals);
createdInvocation = new BoundConstantInvocationExpression(node, constantValue, context.GetTypeSymbol(SpecialType.System_Boolean));
return true;
}

UdonSharpBehaviour TypeSymbol.BaseType is returning null on line 136.
Exception happens on line 139.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions