-
Notifications
You must be signed in to change notification settings - Fork 803
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
error FS1113 accessing constructor parameter with SRTP #15135
Comments
A workaround for this may be to add a But we should definitely fix it. |
Is there any branch having this fixed? Or any progress? |
Still not works in .NET 8. (FSharp.Core 8.0.100) |
Nobody worked on it to my knowledge |
@vzarytovskii If you could give me some hints, e.g. which part one could look into it, I would like to study it and try to fix it? (I mean it needs guidance for one who tries to change code of the compiler (stuff?!) the first time...) |
That's not an easy part of compiler, how I would approach it is see if it changes with different language versions but same sdk (langversion flag, compile same project with different versions), if it is, I would debug in the place it throws an error and see what's different (or alternatively see which language feature causes it). If it still doesn't work with different language versions, it's harder, will have to find what revision of sdk it was working in, check it out and again repeat - see what's different. Maybe even bisect it and see where it started breaking. |
I checked this with .net 5.0.408 and DO see the FS1113 reported by Furthermore, I suspect that the code is indeed invalid, only the error message is misleading. The right one might be the infamous FS0669 ("escape its scope"). Can some expert confirm this? It is happening here. |
Why it is indeed invalid?... Logically it seems good to use.
With .net 8
However even in .net 5, without One of advantage of F# is using compiler to help us do type check/restriction during compilation and this kind of wrapper scinario is really useful... |
I think my guess above about the correct error message was wrong. But I really don't know why your non-inlined example
is shown as invalid, while
compiles. |
The above, though, leads to a workaround for your problem:
(At least for cases where you own the types that you want to instantiate 'T with) |
I think we have established that the FS1113 error (re accessibility) in the original post is correct. |
According to this, I would vote that FS1113 error message is valid as well... |
After some further digging into my earlier question
I found the underlying reason. The CLR that handles generics recognizes a number of constraints, including type/interface constraints, but not explicit member constraints. The latter is a pure F# thing. This means (now I am speculating) the compiler has to express it in IL by an interface constraint, and that can be done only if So, I think we have answered all questions now.
So I guess this issue can be closed? |
Wow!! Sounds reasonable, let me close it! I learned a lot!! |
Repro steps
Expected behavior
Successfully executed.
Actual behavior
Known workarounds
None
Related information
The text was updated successfully, but these errors were encountered: