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.

Inner union compile with error `Cannot implicitly convert type 'X' to 'Y`

See original GitHub issue

Hi. First of all, I’d like to thank you for this excellent library! It is very useful in many contexts! That is great and impressive work! 😃

It would be nice if the inner union classes worked. Below is the example that doesn’t compile

using Dunet;

Console.WriteLine("Hello, World!");

public class Foo
{
    [Union]
    public partial record R
    {
        public partial record O1();
    }

    public R Bar()
    {
        return new R.O1();
    }
}

The error says: Error CS0029 Cannot implicitly convert type 'Foo.R.O1' to 'Foo.R' Although below code works just fine:

using Dunet;

Console.WriteLine("Hello, World!");

[Union]
public partial record R
{
    public partial record O1();
}

public class Foo
{
    public R Bar()
    {
        return new R.O1();
    }
}

I would expect that both variants of code compile. The first version could be useful because the result type can be hidden inside the class. Is it possible to fix that?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KarolBajkowskicommented, Aug 27, 2022

That’s my pleasure 😃 Thank you so much for implementing that feature in such a rapid time period! 😃 🥇 If I find some other reasonable ideas for improvements I’ll come back here if you don’t mind 😉 Take care! 🍻

1reaction
domn1995commented, Aug 27, 2022

@KarolBajkowski v1.2.0 now includes support for this use case. Thanks again for filing this issue and helping review it. Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Cannot implicitly convert type 'customtype' to ' ...
Everything works fine except that I now get this error message on the "return person" in the if statement. Cannot implicitly convert type...
Read more >
Something that confused me a bit when I started doing C# ...
Something that confused me a bit when I started doing C#, "What do you mean 'Cannot implicitly convert type 'x' to 'y', do...
Read more >
Compiler Error CS0266
This error occurs when your code tries to convert between two types that cannot be implicitly converted, but where an explicit conversion is ......
Read more >
Conversion and Promotion - Julia Documentation
In this section, we explain how this promotion system works, as well as how to extend it to new types and apply it...
Read more >
Cannot implicitly convert type 'float' to 'UnityEngine.Vector3 ...
So I am following a Brackeys tutorial about fp movement in unity ([MEDIA]) and as far as I can tell, all of my...
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