| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 556882d commit 1729698
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 13 | 13 | ||
| 14 | 14 | ### Fixed | |
| 15 | 15 | ||
| 16 | + - Fixed error occuring when inheriting a class containing a virtual generic method. | ||
| 17 | + | ||
| 16 | 18 | ## [3.0.1](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.1) - 2022-11-03 | |
| 17 | 19 | ||
| 18 | 20 | ### Added | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -220,7 +220,10 @@ internal static Type CreateDerivedType(string name, | |||
| 220 | 220 | foreach (MethodInfo method in methods) | |
| 221 | 221 | { | |
| 222 | 222 | if (!method.Attributes.HasFlag(MethodAttributes.Virtual) | | |
| 223 | - method.Attributes.HasFlag(MethodAttributes.Final)) | ||
| 223 | + method.Attributes.HasFlag(MethodAttributes.Final) | ||
| 224 | + // overriding generic virtual methods is not supported | ||
| 225 | + // so a call to that should be deferred to the base class method. | ||
| 226 | + || method.IsGenericMethod) | ||
| 224 | 227 | { | |
| 225 | 228 | continue; | |
| 226 | 229 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,4 +136,12 @@ public static T[] EchoRange<T>(T[] items) | |||
| 136 | 136 | return items; | |
| 137 | 137 | } | |
| 138 | 138 | } | |
| 139 | + | ||
| 140 | + public abstract class GenericVirtualMethodTest | ||
| 141 | + { | ||
| 142 | + public virtual Q VirtMethod<Q>(Q arg1) | ||
| 143 | + { | ||
| 144 | + return arg1; | ||
| 145 | + } | ||
| 146 | + } | ||
| 139 | 147 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | import System | |
| 10 | 10 | import pytest | |
| 11 | 11 | from Python.Test import (IInterfaceTest, SubClassTest, EventArgsTest, | |
| 12 | - FunctionsTest, IGenericInterface) | ||
| 12 | + FunctionsTest, IGenericInterface, GenericVirtualMethodTest) | ||
| 13 | 13 | from System.Collections.Generic import List | |
| 14 | 14 | ||
| 15 | 15 | ||
@@ -327,3 +327,15 @@ def test_generic_interface(): | |||
| 327 | 327 | obj = GenericInterfaceImpl() | |
| 328 | 328 | SpecificInterfaceUser(obj, Int32(0)) | |
| 329 | 329 | GenericInterfaceUser[Int32](obj, Int32(0)) | |
| 330 | + | ||
| 331 | + def test_virtual_generic_method(): | ||
| 332 | + class OverloadingSubclass(GenericVirtualMethodTest): | ||
| 333 | + __namespace__ = "test_virtual_generic_method_cls" | ||
| 334 | + class OverloadingSubclass2(OverloadingSubclass): | ||
| 335 | + __namespace__ = "test_virtual_generic_method_cls" | ||
| 336 | + obj = OverloadingSubclass() | ||
| 337 | + assert obj.VirtMethod[int](5) == 5 | ||
| 338 | + obj = OverloadingSubclass2() | ||
| 339 | + assert obj.VirtMethod[int](5) == 5 | ||
| 340 | + | ||
| 341 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments