question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compilers fails to compile module with same name as Record using Unit of Measure generic type declared before

See original GitHub issue

Please provide a succinct description of the issue.

Repro steps

Provide the steps required to reproduce the problem:

  1. Copy the following code into a .fsx or .fs file:
type Animal<[<Measure>] 'Measure> =
    {
        Size : float
    }

module Animal =

    let create (s: float<'Measure>) : Animal<'Measure> =
        { Size = float s }
  1. Observe that the compiler throws an error for the Animal module.

If possible attach a zip file with the repro case. This often makes it easier for others to reproduce. The zip file should ideally represent the situation just before the call/step that is problematic.

Expected behavior

The compiler should compile.

Actual behavior

Compiler says there is a duplicate definition of the Animal type

Known workarounds

Annotate the Animal module with the [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] attribute.

Related information

Provide any related information (optional):

  • Operating system
  • .NET Runtime kind (.NET Core, .NET Framework, Mono)
  • Editing Tools (e.g. Visual Studio Version, Visual Studio)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
T-Grocommented, Nov 4, 2022

Matt:

In SyntaxTree, the typar (TYpeARgument) has the following shape, with attributes on it: [<NoEquality; NoComparison>] type SynTyparDecl = SynTyparDecl of attributes: SynAttributes * SynTypar

So this check should be possible.

Here is what I would do: Add new test-file by mimicing what the neighborhood tests are doing, I would place this one at : \tests*FSharp.Compiler.ComponentTests*\Conformance*UnitsOfMeasure*\

Cover the following via separate test cases (in the end almost identical)

  • Non-generic record + module // erasure IS needed
  • Classical generic record + module // erasure not needed
  • UoM-generic record + module // erasure IS needed
  • Record having both UoM generics and regular generics + module // erasure not needed

And add a breakpoint to the set-building function above and inspect. Focus on the SynComponentInfo(typeParams=TyparDecls typars and if isNil typars then parts

0reactions
0101commented, Nov 28, 2022

This doesn’t seem to reproduce anymore in latest F#/VS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generic method does not compile when passed a ...
I have included a simplified version of the issue. In the following example, the program will not compile because of the method broken...
Read more >
What I wish I knew when learning F#
F# uses a lot of top level values and functions and so F# introduced modules since Namespaces can't contain them directly. These do...
Read more >
1 Compiler Release Notes
1.2 Compiler 7.1.4. Fixed Bugs and Malfunctions. The 'deterministic' option was not recognized when given in a -compile() attribute in the source code....
Read more >
F# coding conventions
FSharp.Collections.List module has this attribute. This is useful when functions and values in the module have names that are likely to conflict ...
Read more >
Using the GNU Compiler Collection
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found