vrchat-community / UdonSharp

A compiler for compiling C# to Udon assembly
https://udonsharp.docs.vrchat.com
MIT License
467 stars 50 forks source link

Add support for searching for alternate invocees for externs #11

Closed bdunderscore closed 2 years ago

bdunderscore commented 2 years ago

For certain C# methods, Udon exposes the method via a different type than Roslyn considers it to be defined on. One example is System.Type.Name, which is actually defined in System.Reflection.MemberInfo, but exposed via System.Type.Name.

This change allows U# to locate these alternate extern symbols and use them transparently. We move the logic for checking whether symbols are exposed to udon down into BoundExternMethodInvocation, then teach this class to search declared interfaces and superclasses of the invocation target (rather than the symbol's containing type) for defined externs.

Note that we assume that any exposed extern will match if we find it via a constructed symbol here.

Note: This is more-or-less a straight rebase of https://github.com/MerlinVR/UdonSharp/pull/129 . I'm currently unable to add new tests to the integration test scene on this branch, due to what I suspect are issues related to the serialization branch. For now I'm putting this PR up in case you can get the test suite working on your machine; it at least does not seem to cause new regressions.