You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This ticket suggests that this should work from 9.0 Preview 4, however this fails in 9.0 GA:
using System.Runtime.CompilerServices;// this works fine
Console.WriteLine(Hack.CreateFoo());// this doesn't work
Console.WriteLine(Hack.CreateBar<int>());// this doesn't workBar<int>evil=(Bar<int>)RuntimeHelpers.GetUninitializedObject(typeof(Bar<int>));
Hack.HacketyHackHack(evil);
Console.WriteLine(evil);staticclassHack{[UnsafeAccessor(UnsafeAccessorKind.Constructor)]internalstaticextern Foo CreateFoo();[UnsafeAccessor(UnsafeAccessorKind.Method, Name =".ctor")]internalexternstaticvoidHacketyHackHack<T>(Bar<T>obj);[UnsafeAccessor(UnsafeAccessorKind.Constructor)]internalstaticexternBar<T>CreateBar<T>();}classFoo{privatereadonlystrings=".ctor has run";publicoverridestringToString()=> s;privateFoo(){}}classBar<T>{privatereadonlystrings=".ctor has run; "+typeof(T).Name;publicoverridestringToString()=> s;privateBar(){}}
Reproduction Steps
as above
Expected behavior
it works
Actual behavior
Unhandled exception. System.InvalidProgramException: Generic type constraints do not match.
at Hack.CreateBar[T]()
at Program.<Main>$(String[] args) in C:\Users\marcg\source\repos\ConsoleApp4\ConsoleApp4\Program.cs:line 7
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered:
using System;using System;using System.Runtime.CompilerServices;Hack<int>.CreateBar();Bar<int>evil=(Bar<int>)RuntimeHelpers.GetUninitializedObject(typeof(Bar<int>));
Console.WriteLine(Hack<short>.CreateBar());Hack<int>.HacketyHackHack(evil);
Console.WriteLine(evil);staticclassHack<T>{[UnsafeAccessor(UnsafeAccessorKind.Method, Name =".ctor")]internalexternstaticvoidHacketyHackHack(Bar<T>obj);[UnsafeAccessor(UnsafeAccessorKind.Constructor)]internalstaticexternBar<T>CreateBar();}classBar<T>{privatereadonlystrings=".ctor has run; "+typeof(T).Name;publicoverridestringToString()=> s;privateBar(){}}
Description
This ticket suggests that this should work from 9.0 Preview 4, however this fails in 9.0 GA:
Reproduction Steps
as above
Expected behavior
it works
Actual behavior
Unhandled exception. System.InvalidProgramException: Generic type constraints do not match. at Hack.CreateBar[T]() at Program.<Main>$(String[] args) in C:\Users\marcg\source\repos\ConsoleApp4\ConsoleApp4\Program.cs:line 7
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: