Skip to content

Commit a6ec5df

Browse files
committed
Add checks to make sure the user is inheriting from UdonSharpBehaviour
- Add checks to enforce inheriting UdonSharpBehaviours from UdonSharpBehaviour to avoid the program breaking for unclear reasons
1 parent 69b2d12 commit a6ec5df

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,44 @@ public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
180180
namespaceStack.Pop();
181181
}
182182

183+
public override void VisitSimpleBaseType(SimpleBaseTypeSyntax node)
184+
{
185+
UpdateSyntaxNode(node);
186+
187+
Visit(node.Type);
188+
}
189+
190+
public override void VisitBaseList(BaseListSyntax node)
191+
{
192+
UpdateSyntaxNode(node);
193+
194+
foreach (BaseTypeSyntax type in node.Types)
195+
{
196+
using (ExpressionCaptureScope typeCaptureScope = new ExpressionCaptureScope(visitorContext, null))
197+
{
198+
Visit(type);
199+
200+
if (typeCaptureScope.captureType.IsInterface)
201+
{
202+
throw new System.NotSupportedException("UdonSharp does not yet support inheriting from interfaces");
203+
}
204+
else if (typeCaptureScope.captureType != typeof(UdonSharpBehaviour))
205+
{
206+
if (typeCaptureScope.captureType == typeof(MonoBehaviour))
207+
throw new System.NotSupportedException("UdonSharp behaviours must inherit from 'UdonSharpBehaviour' instead of 'MonoBehaviour'");
208+
209+
throw new System.NotSupportedException("UdonSharp does not yet support inheriting from classes other than 'UdonSharpBehaviour'");
210+
}
211+
}
212+
}
213+
}
214+
183215
public override void VisitClassDeclaration(ClassDeclarationSyntax node)
184216
{
185217
UpdateSyntaxNode(node);
186218

219+
Visit(node.BaseList);
220+
187221
using (ExpressionCaptureScope selfTypeCaptureScope = new ExpressionCaptureScope(visitorContext, null))
188222
{
189223
foreach (string namespaceToken in namespaceStack.Reverse())

0 commit comments

Comments
 (0)