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.

Exception when comparing generated map containing private DU

See original GitHub issue

I ran into an exception when running following test:

Message: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ---- System.ArgumentException : The type ‘SiteAgent.MessageGateway.Server.Tests.Foo+Bar’ is an F# union type but its representation is private. You must specify BindingFlags.NonPublic to access private type representations. Parameter name: unionType

open FsCheck
open FsCheck.Xunit

module Foo =
    type Bar = private Bar of string
    let create bar = Bar bar

module DataTests =
    [<Property>]
    let ``empty = generated nonEmpty`` (bars: Map<Foo.Bar, string>) =
        not (bars.IsEmpty) ==> lazy
        let emptyMap : Map<Foo.Bar, string> = Map.empty
        emptyMap = bars

When the map is created inside the test it fails correctly without the exception:

    [<Property>]
    let ``empty = nonEmpty``() =
        let bar = Foo.create "bar"
        let nonEmptyMap = Map [ bar, "bar" ]
        let emptyMap : Map<Foo.Bar, string> = Map.empty
        emptyMap = nonEmptyMap

map [] = map [(Bar “bar”, “bar”)] false Expected: True Actual: False

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kurtschelfthoutcommented, May 29, 2018

Let’s say we’re considering whether to add it and if yes, how to add automatic generation/shrinking for private types. Imo we can add it but we should make it opt-in.

Meanwhile I’ll close this, as I don’t want to duplicate the discussion here. Feel free to add any thoughts to the other discussion, or re-open if there is anything unrelated that you still have a problem with.

0reactions
jbezakcommented, May 28, 2018

If I understand the pull request you’ve mentioned correctly it actually adds the functionality to generate private DU. That is also what I am seeing when debugging the tests.

I realized that the exception does not occur during the generation but during shrinking for failed tests. This test is passing but when it fails, shrinking will not help me to find the failing values.

  [<Property>]
  let ``generating nonEmpty`` (bars: Map<Foo.Bar, string>) =
      not (bars.IsEmpty) ==> lazy
      not bars.IsEmpty
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to compare the values of 2 Maps Java
The intersection of the key sets of the maps is the set to be iterated, and if the value from map 1 and...
Read more >
Heterogeneous sorted containers should only be used with ...
With heterogeneous containers, the previous code will not create a string , but directly compare keys in the map with the searched char...
Read more >
Tired of Null Pointer Exceptions? Consider Using Java SE ...
The variable computer is of type Optional<Computer> , so it is perfectly correct to call the map method. However, getSoundcard() returns an object...
Read more >
@EqualsAndHashCode
Any class definition may be annotated with @EqualsAndHashCode to let lombok generate implementations of the equals(Object other) and hashCode() methods.
Read more >
MapStruct 1.5.5.Final Reference Guide
Compared to writing mapping code from hand, MapStruct saves time by generating code which is tedious and error-prone to write.
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