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
{{ message }}
Repository navigation
Build fails without prior feed-back when reusing names for DU constructors and IWSAM members #14321
typeSensorReadings= int
typeEngineError<'e>=static abstractOverheated :'estatic abstractLowOil :'eletstartEngine<'ewhenEngineError<'e>>(sensorReading :SensorReadings):Result<unit,'e>=if sensorReading <=10then Error 'e.Overheated
elif sensorReading <=20then Error 'e.LowOil
else Ok ()typeAudioError<'e>=static abstractDeviceNotPaired :'eletinitializeAudio<'ewhenAudioError<'e>>(sensorReading :SensorReadings):Result<unit,'e>=if sensorReading <=30then Error 'e.DeviceNotPaired else Ok ()typeCarError2=| Overheated2
| LowOil2
| DeviceNotPaired2
interface EngineError<CarError2>withstatic memberOverheated= Overheated2
static memberLowOil= LowOil2
// There seems to be a compiler bug here. An interesting error is produced very late during// building if "2" is removed from DU constructor names. I expect it to be possible to// reuse the names, as normally possible in F#.interface AudioError<CarError2>withstatic memberDeviceNotPaired= DeviceNotPaired2
letstartCar(sensorReading :SensorReadings):Result<unit,CarError2>= result {// Prioritize engine errors above audio errorsdo! startEngine sensorReading
do! initializeAudio sensorReading
}
Note the "2" in the naming of DU constructors and the note above. When leaving the "2"s out, Visual Studio does not provide any feed-back (warning, etc.) so everything seems OK. However, building produces the following seemingly very low-level error:
Build started...
1>------ Build started: Project: IWSAMDemo, Configuration: Debug Any CPU ------
1>FSC : error FS2014: A problem occurred writing the binary 'obj\Debug\net7.0\refint\IWSAMDemo.dll': Error in pass2 for type ErrorMerging, error: Error in pass2 for type CarError2, error: duplicate entry 'Overheated' in property table
1>Done building project "IWSAMDemo.fsproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Elapsed 00:01,464 ==========
typeInterface=static abstractCase:ImplementationandImplementation=| Case
interface Interface withstatic memberCase= Case
When static member name is the same as DU case name and the type of the field is DU, it fails to create the second one.
It was the case even before IWSAMs, but we have a better error for it:
typeImplementation=| Case
static memberCase= Case
will produce
>typeImplementation=-| Case
-static memberCase= Case;;static memberCase= Case;;------------------^^^^
stdin(100,19): error FS0023: The member 'Case' can not be defined because the name 'Case' clashes with the union case 'Case' in this type or module
Not much we can do to allow it, just make the error better.
Update: or alternatively, we could store explicit interface properties (static Implementation Interface.Case => Case;) differently (i.e. using their full name), since it might be a valid use case (however, names+types clash would be rather rare, I guess).
I'm a little surprised we're not emitting an explicit method impl for these cases. I don't see any intrinsic reason why it shouldn't be compilable if we did?
Activity
vzarytovskii commentedon Nov 15, 2022
Oh, that's an interesting one @dsyme.
Phase2 confuses the DU constructor and property from interface in the properties table.
vzarytovskii commentedon Nov 16, 2022
Minimal repro:
When static member name is the same as DU case name and the type of the field is DU, it fails to create the second one.
It was the case even before IWSAMs, but we have a better error for it:
will produce
Not much we can do to allow it, just make the error better.
Update: or alternatively, we could store explicit interface properties (
static Implementation Interface.Case => Case;) differently (i.e. using their full name), since it might be a valid use case (however, names+types clash would be rather rare, I guess).dsyme commentedon Nov 16, 2022
I'm a little surprised we're not emitting an explicit method impl for these cases. I don't see any intrinsic reason why it shouldn't be compilable if we did?
That is, for the interface implementations
vzarytovskii commentedon Nov 16, 2022
We do, for
We will emit something like:
Yeah, I think it's the name we use in ilwrite when store properties.
edgarfgp commentedon Jan 10, 2025
@vzarytovskii Im trying to understand if this fixable. If so, I would love some guidance if you have sometime.
vzarytovskii commentedon Jan 10, 2025
It is. I'll need to re-investigate it to freshen my memory about it.
edgarfgp commentedon Jan 10, 2025
Thanks @vzarytovskii.
Complete codegen regression test suite: add remaining 32 issues
Sprint 4: Improve tests for issues #14707, #14706, #14508, #14492, #1…
Fix #14321: DU case names matching IWSAM member names no longer cause…
Fix DU duplicate methods, event metadata
Fix DU duplicate methods, event metadata
Fix DU duplicate methods, event metadata
Fix DU duplicate methods, event metadata
Fix DU duplicate methods, event metadata
Fix DU duplicate methods, event metadata
Address review: remove leftover files, add IL verification tests