mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix(weaver): Warning for multiple write/read functions for the same type (#2453)
* fix(weaver): Warning for multiple write/read functions for the same type Adding warning message when trying to register a write or read function for a type that is already in dictionary. Previously weaver would be silent about this making it hard to know when an extension method overrides another one. * test for warnings
This commit is contained in:
parent
fd9a7b0561
commit
301e791d9d
@ -17,6 +17,12 @@ public static void Init()
|
||||
|
||||
internal static void Register(TypeReference dataType, MethodReference methodReference)
|
||||
{
|
||||
string typeName = dataType.FullName;
|
||||
if (readFuncs.ContainsKey(typeName))
|
||||
{
|
||||
Weaver.Warning($"Registering a Read method for {typeName} when one already exists", methodReference);
|
||||
}
|
||||
|
||||
readFuncs[dataType.FullName] = methodReference;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,13 @@ public static void Init()
|
||||
|
||||
public static void Register(TypeReference dataType, MethodReference methodReference)
|
||||
{
|
||||
writeFuncs[dataType.FullName] = methodReference;
|
||||
string typeName = dataType.FullName;
|
||||
if (writeFuncs.ContainsKey(typeName))
|
||||
{
|
||||
Weaver.Warning($"Registering a Write method for {typeName} when one already exists", methodReference);
|
||||
}
|
||||
|
||||
writeFuncs[typeName] = methodReference;
|
||||
}
|
||||
|
||||
static void RegisterWriteFunc(TypeReference typeReference, MethodDefinition newWriterFunc)
|
||||
|
@ -133,6 +133,7 @@
|
||||
<Compile Include="WeaverCommandTests~\ErrorForOptionalNetworkConnectionThatIsNotSenderConnection.cs" />
|
||||
<Compile Include="WeaverGeneralTests~\RecursionCount.cs" />
|
||||
<Compile Include="WeaverGeneralTests~\TestingScriptableObjectArraySerialization.cs" />
|
||||
<Compile Include="WeaverGeneratedReaderWriterTests~\GivesWarningWhenRegisteringExistingExtensionMethod.cs" />
|
||||
<Compile Include="WeaverMessageTests~\AbstractMessageMethods.cs" />
|
||||
<Compile Include="WeaverMessageTests~\MessageMemberGeneric.cs" />
|
||||
<Compile Include="WeaverMessageTests~\MessageMemberInterface.cs" />
|
||||
|
@ -203,5 +203,16 @@ public void GivesErrorForInvalidListType()
|
||||
//HasError("Cannot generate reader for List because element MonoBehaviour does not have a reader. Use a supported type or provide a custom reader",
|
||||
// "System.Collections.Generic.List`1<UnityEngine.MonoBehaviour>");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GivesWarningWhenRegisteringExistingExtensionMethod()
|
||||
{
|
||||
const string typeName = "GeneratedReaderWriter.GivesWarningWhenRegisteringExistingExtensionMethod.MyType";
|
||||
HasNoErrors();
|
||||
HasWarning($"Registering a Write method for {typeName} when one already exists",
|
||||
"System.Void GeneratedReaderWriter.GivesWarningWhenRegisteringExistingExtensionMethod.ReadWriteExtension::WriteMyType2(Mirror.NetworkWriter,GeneratedReaderWriter.GivesWarningWhenRegisteringExistingExtensionMethod.MyType)");
|
||||
HasWarning($"Registering a Read method for {typeName} when one already exists",
|
||||
"GeneratedReaderWriter.GivesWarningWhenRegisteringExistingExtensionMethod.MyType GeneratedReaderWriter.GivesWarningWhenRegisteringExistingExtensionMethod.ReadWriteExtension::ReadMyType2(Mirror.NetworkReader)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
using Mirror;
|
||||
|
||||
namespace GeneratedReaderWriter.GivesWarningWhenRegisteringExistingExtensionMethod
|
||||
{
|
||||
public struct MyType
|
||||
{
|
||||
public int number;
|
||||
}
|
||||
|
||||
public static class ReadWriteExtension
|
||||
{
|
||||
public static void WriteMyType(this NetworkWriter writer, MyType data)
|
||||
{
|
||||
writer.WriteInt32(data.number);
|
||||
}
|
||||
|
||||
public static void WriteMyType2(this NetworkWriter writer, MyType data)
|
||||
{
|
||||
writer.WriteInt32(data.number);
|
||||
}
|
||||
|
||||
public static MyType ReadMyType(this NetworkReader reader)
|
||||
{
|
||||
return new MyType { number = reader.ReadInt32() };
|
||||
}
|
||||
|
||||
public static MyType ReadMyType2(this NetworkReader reader)
|
||||
{
|
||||
return new MyType { number = reader.ReadInt32() };
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user