-
Notifications
You must be signed in to change notification settings - Fork 805
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
Build fails with Error FS2014, error: MethodDef not found when using static abstract stuff #15919
Comments
To add: it affects only reference assembly generation, turning refassemblies off should be a feasible workaround until it's fixed. |
@vzarytovskii Maybe I did something wrong, but turning off reference assembly generation did not help but the error message changed slightly |
It seems like is set to false by default
With explicitly set true
Note that when producing reference assembly, the only difference is "refinit" is in the path. Also, file name is not the full path but relative for some reason. I'm not sure this is a regression because it's reproduceable both on .Net 7 and .Net 8. P.S. It seems like I did post errors above from my main solution but repro project behaves the same. Sorry for confusion. |
@vzarytovskii I can confirm reference assemblies have nothing to do with this again. I've managed to come up with a minimal repro. This is clearly a compiler bug. a minimal repro: type IHasStaticAbstractBase<'a> =
static abstract Boom: unit -> 'a
type IHasStaticAbstractChild<'a> =
inherit IHasStaticAbstractBase<'a>
type CompilerGoesBoom<'a>() =
interface IHasStaticAbstractChild<'a> with // this goes boom because inheritance is involved
static member Boom() = Unchecked.defaultof<'a>
type CompilerDoesNotGoBoom<'a>() =
interface IHasStaticAbstractBase<'a> with // this does not go boom, direct base interface
static member Boom() = Unchecked.defaultof<'a> My best guess is that it is trying to find |
Can we change the impact? |
Impact is internal for our own usage only. It mostly means it doesn't impact any existing code. |
@vzarytovskii Why do you think it's internal? As I said, reference assembly generation has nothing to do with this. Whole build simply fails if you use inheritance with static abstracts. I found this bug while writing my own code, not while tinkering with core lib or something like that Or maybe I've misunderstood and "impact" itself is an internal marker for the team. This is sort of confusing. Anyway, I don't think it's that "low". If it was about reference assemblies for example and there was a clear workaround (like just turn them off and be done with it, build is ok) then it might be "low". But this one has no workarounds except for "well, don't use that". |
Why do I think that "impact" label is for internal use only? Well, because it is.
Again, it does not reflect severity, or importance, or anything. To reiterate: PLEASE, DON'T LOOK AT IMPACT TAGS AS IS THEY REFLECT SEVERITY OF BUGS |
InvestigationNon-static abstractInfo
Mdefs
Writing mdefs
Static abstractInfo
Mdefs
Writing mdefs
DifferencesMethod getting emitted in case of
Just
Lookup is, however, trying to search for |
The bug is that we don't generate fixups method rename fixup for the static abstracts here: fsharp/src/Compiler/CodeGen/IlxGen.fs Lines 9214 to 9221 in f88d5d4
like we do it for normal slots here: fsharp/src/Compiler/CodeGen/IlxGen.fs Lines 9227 to 9246 in f88d5d4
|
That would be the fix, I think. If someone wants to make the fix + few tests: diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs
index 33b39ce7f..a987b78ab 100644
--- a/src/Compiler/CodeGen/IlxGen.fs
+++ b/src/Compiler/CodeGen/IlxGen.fs
@@ -9212,7 +9212,13 @@ and GenMethodForBinding
if not memberInfo.MemberFlags.IsOverrideOrExplicitImpl then
mkILStaticMethod (ilMethTypars, mspec.Name, access, ilParams, ilReturn, ilMethodBody)
else // We want to get potential fixups and hidebysig for abstract statics:
- let flagFixups = [ fixupStaticAbstractSlotFlags ]
+ let flagFixups =
+ [
+ fixupStaticAbstractSlotFlags
+ match ComputeMethodImplNameFixupForMemberBinding cenv v with
+ | Some nm -> renameMethodDef nm
+ | None -> ()
+ ]
let mdef =
mkILStaticMethod (ilMethTypars, mspec.Name, access, ilParams, ilReturn, ilMethodBody) Otherwise, I can make it next week once I'm back. |
Maybe we should a severity tag. @vzarytovskii good job finding the root cause. I was researching it as well, but you are miles ahead. I will create a PR with a fix. |
@vzarytovskii Thank you |
Stumbled upon this recently when trying to make C#-like task builder which only requires the user to define awaiter, builder and task types
Repro steps
Extract the archive, try to build the solution
ClassLibrary1.zip
Tried it with net7 and net8 without any luck
The text was updated successfully, but these errors were encountered: