🌐 AI搜索 & 代理 主页
Skip to content

Commit 0c99551

Browse files
rmadsen-ksfilmor
authored andcommitted
Added fix for calling virtual method on baseclass which is not defined.
1 parent e762072 commit 0c99551

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/runtime/Types/ClassDerived.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private static void AddVirtualMethod(MethodInfo method, Type baseType, TypeBuild
396396
string? baseMethodName = null;
397397
if (!method.IsAbstract)
398398
{
399-
baseMethodName = "_" + baseType.Name + "__" + method.Name;
399+
baseMethodName = "_" + method.DeclaringType.Name + "__" + method.Name;
400400
MethodBuilder baseMethodBuilder = typeBuilder.DefineMethod(baseMethodName,
401401
MethodAttributes.Public |
402402
MethodAttributes.Final |

src/testing/classtest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,9 @@ public virtual string SayGoodbye()
7676
return "!";
7777
}
7878
}
79+
80+
public class SimpleClass2 : SimpleClass
81+
{
82+
// this class does not override SayGoodbye.
83+
}
7984
}

tests/test_subclass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import System
1010
import pytest
1111
from Python.Test import (IInterfaceTest, SubClassTest, EventArgsTest,
12-
FunctionsTest, IGenericInterface, GenericVirtualMethodTest, SimpleClass, ISayHello1)
12+
FunctionsTest, IGenericInterface, GenericVirtualMethodTest, SimpleClass, SimpleClass2, ISayHello1)
1313
from System.Collections.Generic import List
1414

1515

@@ -355,7 +355,7 @@ def test_multi_level_subclass():
355355
exception if a method was not implemented in the middle of the tree.
356356
"""
357357
import clr
358-
class DualSubClass0(ISayHello1, SimpleClass):
358+
class DualSubClass0(ISayHello1, SimpleClass2):
359359
__namespace__ = "Test"
360360
def SayHello(self):
361361
return "hello"

0 commit comments

Comments
 (0)