Title: Generated get/set methods incorrectly marked non-virtual · Issue #8302 · PowerShell/PowerShell · GitHub
Open Graph Title: Generated get/set methods incorrectly marked non-virtual · Issue #8302 · PowerShell/PowerShell
X Title: Generated get/set methods incorrectly marked non-virtual · Issue #8302 · PowerShell/PowerShell
Description: While testing an experimental feature to add support for interface declarations, I found that types generated using the class keyword can't correctly override get/set methods associated with properties. Steps to reproduce Add-Type @' nam...
Open Graph Description: While testing an experimental feature to add support for interface declarations, I found that types generated using the class keyword can't correctly override get/set methods associated with proper...
X Description: While testing an experimental feature to add support for interface declarations, I found that types generated using the class keyword can't correctly override get/set methods associated with pr...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/8302
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generated get/set methods incorrectly marked non-virtual","articleBody":"While testing an experimental feature to [add support for interface declarations](https://github.com/PowerShell/PowerShell/issues/2223#issuecomment-439602845), I found that types generated using the `class` keyword can't correctly override get/set methods associated with properties.\r\n\r\n# Steps to reproduce\r\n\r\n```powershell\r\nAdd-Type @'\r\nnamespace TypeTest {\r\n public interface Interface {\r\n string S { get; set; }\r\n }\r\n}\r\n'@\r\n\r\n# Execute this as a separate statement to ensure TypeTest.Interface is defined before the class definition is\r\nclass TestClass : TypeTest.Interface {\r\n [string]$S\r\n}\r\n\r\n```\r\n\r\n# Expected behavior\r\n\r\nNew type `[TestClass]` implementing `[TypeTest.Interface]` should have been compiled and loaded.\r\n\r\n# Actual behavior\r\n\r\n```none\r\nAt line:1 char:1\r\n+ class TestClass : TypeTest.Interface {\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\nError during creation of type \"TestClass\". Error message:\r\nMethod 'get_S' in type 'TestClass' from assembly 'Powershell Class Assembly, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null' does not have an implementation.\r\n + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException\r\n + FullyQualifiedErrorId : TypeCreationError\r\n```\r\n\r\n# Solution\r\n\r\nAfter comparing the CIL emitted by the C# compiler when implicitly implementing an interface property, I found that the get/set methods generated by the compiler are marked `virtual`.\r\n\r\nThe fix is to either attempt to discover properties with matching signatures in associated instances and mark the backing get/set methods `virtual`, or simply just mark *all* get/set methods `virtual` (might incur slight overhead in method resolution at runtime rather than at compile time)\r\n\r\n# Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```none\r\n\r\nName Value\r\n---- -----\r\nPSVersion 6.2.0-preview.1\r\nPSEdition Core\r\nGitCommitId 6.2.0-preview.1-79-g16569b157a430cc5d4a2e7bf189dcfef64beb31f\r\nOS Microsoft Windows 10.0.17134 \r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n","author":{"url":"https://github.com/IISResetMe","@type":"Person","name":"IISResetMe"},"datePublished":"2018-11-17T15:53:23Z","url":"https://github.com/PowerShell/PowerShell/issues/8302"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7947f7b5-f91a-5627-9503-9d0ecde8a14e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 854C:3E0E71:70A885:9E6476:6AFDC0BD |
| html-safe-nonce | f03c057a1d942a6344c7cfb728364a238d9c49448cc0e9bb41603ac5c2c65031 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTRDOjNFMEU3MTo3MEE4ODU6OUU2NDc2OjZBRkRDMEJEIiwidmlzaXRvcl9pZCI6IjgzOTgwNjcxNDc1NzM0MTIwMjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 34df8db9b43bce40c9dc0798d290f12dd38191d375cd5cc925c71ac782d5b8d6 |
| hovercard-subject-tag | issue:381874938 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/8302/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7d6b08414d49663d68eba731a32ced5583ca2527d4e93cd98840aa1b94361380/PowerShell/PowerShell/issues/8302 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7d6b08414d49663d68eba731a32ced5583ca2527d4e93cd98840aa1b94361380/PowerShell/PowerShell/issues/8302 |
| og:image:alt | While testing an experimental feature to add support for interface declarations, I found that types generated using the class keyword can't correctly override get/set methods associated with proper... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | IISResetMe |
| hostname | github.com |
| expected-hostname | github.com |
| None | 35c6bf57da1370dc64866160540c0ee9f825f291935b3bf6ec5492b00e35f3a6 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ab48c73a2978548773f5f24717ed9e58508befdb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width