Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

1776 Generic Virtual Method Causes Invalid Program: Fix + test#2026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].

### Fixed

- Fixed error occuring when inheriting a class containing a virtual generic method.

## [3.0.1](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.1) - 2022-11-03

### Added
Expand Down
5 changes: 4 additions & 1 deletionsrc/runtime/Types/ClassDerived.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -220,7 +220,10 @@ internal static Type CreateDerivedType(string name,
foreach (MethodInfo method in methods)
{
if (!method.Attributes.HasFlag(MethodAttributes.Virtual) |
method.Attributes.HasFlag(MethodAttributes.Final))
method.Attributes.HasFlag(MethodAttributes.Final)
// overriding generic virtual methods is not supported
// so a call to that should be deferred to the base class method.
|| method.IsGenericMethod)
{
continue;
}
Expand Down
8 changes: 8 additions & 0 deletionssrc/testing/generictest.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,4 +136,12 @@ public static T[] EchoRange<T>(T[] items)
return items;
}
}

public abstract class GenericVirtualMethodTest
{
public virtual Q VirtMethod<Q>(Q arg1)
{
return arg1;
}
}
}
14 changes: 13 additions & 1 deletiontests/test_subclass.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
import System
import pytest
from Python.Test import (IInterfaceTest, SubClassTest, EventArgsTest,
FunctionsTest, IGenericInterface)
FunctionsTest, IGenericInterface, GenericVirtualMethodTest)
from System.Collections.Generic import List


Expand DownExpand Up@@ -327,3 +327,15 @@ def test_generic_interface():
obj = GenericInterfaceImpl()
SpecificInterfaceUser(obj, Int32(0))
GenericInterfaceUser[Int32](obj, Int32(0))

def test_virtual_generic_method():
class OverloadingSubclass(GenericVirtualMethodTest):
__namespace__ = "test_virtual_generic_method_cls"
class OverloadingSubclass2(OverloadingSubclass):
__namespace__ = "test_virtual_generic_method_cls"
obj = OverloadingSubclass()
assert obj.VirtMethod[int](5) == 5
obj = OverloadingSubclass2()
assert obj.VirtMethod[int](5) == 5



[8]ページ先頭

©2009-2025 Movatter.jp