-
Notifications
You must be signed in to change notification settings - Fork 304
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic Base type parameterized with its inheritor => Stack Overflow on .GetType() of inheritor value #3607
Comments
Note that only attempt to work with runtime type info results in stack overflow. It is still possible to construct and use the value, for example: [<AbstractClass>]
type Base<'Inheritor when 'Inheritor :> Base<'Inheritor>> () =
member _.Dummy() = 1
type Inheritor() = inherit Base<Inheritor>()
let i = new Inheritor()
printf "hello world"
printf $"Dummy value: {i.Dummy()}"
printf "goodbye world" prints
as expected However in my case it is mission critical to have working runtime type info (specifically for Thoth JSON encoding via Encoding.Auto) |
This one is tricky. The problem comes from this function: export function Inheritor_$reflection() {
return class_type("Test.Inheritor", void 0, Inheritor, Base$1_$reflection(Inheritor_$reflection()));
} Which as you can see reference itself and this is what is causing the StackOverflow. Perhaps, we need to look if we can use a |
why not just pass a null parent and then set it afterwards like this (pseudocode) export function Inheritor_$reflection() {
var x = class_type("Test.Inheritor", void 0, Inheritor, null);
x.Parent = Base$1_$reflection(x);
return x;
} |
Perhaps this can works, I am wondering if there are edges cases where this would not work or not. I suppose the CI will tells us if this cause a regression or not, if it doesn't we will go with it unless another maintainer has another solutions. I am not yet familiar will the requirements of Fable reflection |
sure, I'm not familiar with the code at all, and there might be other code paths that try to traverse reflection type hierarchy without the loop check, which also might stack overflow or hang, but at very least it will happen later |
Description
Given a simple generic type hierarchy, where
Base<>
type is parameterized with itsInheritor
type, it is possible to construct and use a value ofInheritor
, but attempt to get runtime.GetType()
results in stack overflow.Repro code
Go to https://fable.io/repl/
Expected and actual results
Expected results:
Actual results:
Nothing printed, in Chrome dev tools Console following is found:
Related information
Fable version:
dotnet fable --version
3.7.20
Operating system
Windows 11 Pro
but probably will reproduce elsewhere
The text was updated successfully, but these errors were encountered: