Giter Club home page Giter Club logo

Comments (6)

laytan avatar laytan commented on August 29, 2024 1

Ok got it down to this repro:

package bug

Bar :: union {
	int,
}

Foo :: union {
	Bar,
}

FooBar :: struct {
	foo: Foo,
}

main :: proc() {
	foo := FooBar {
		foo = 69, // Make this `Bar(69)` and it fixes it.
	}
	assert(foo.foo != nil)
}

It has to do with this hack:

// HACK TODO(bill): THIS IS A MASSIVE HACK!!!!

Adding a panic at types.cpp:3005 confirms the issue: GB_PANIC("type %s is not a variant of the union %s!\n", type_to_string(v), type_to_string(u));

This hack evidently does not work with nested unions.

I ran out of time to think of a fix (would probably be some kind of recursive/looping solution to account for multiple levels) so I am leaving this info here.

from odin.

laytan avatar laytan commented on August 29, 2024

Can you give us some code that triggers the assert in your linked repo, like a main proc that calls the procedure that asserts in it?

from odin.

xzores avatar xzores commented on August 29, 2024

You will find it in regui/GUI.odin and then in the init function.

from odin.

laytan avatar laytan commented on August 29, 2024

Yes but just putting a main proc that imports and calls that doesn't work and fails with errors about a missing package ex_defs

from odin.

xzores avatar xzores commented on August 29, 2024

Hmm, I don't experience this, as you can see in my project it seems to work fine for the double union (the "default" struct member), but it does not work for the Maybe and then double union (The "hover" and "active" struct memebers.)

Here is the struct for clarification:

Style :: struct {
	default : Appearance,            //Works
	hover : Maybe(Appearance), //Does not work
	active : Maybe(Appearance), //Does not work
}

Appearance :: union {
	Colored_appearance,
	Patched_appearance,
	Textured_appearance,
}

from odin.

laytan avatar laytan commented on August 29, 2024

Don't experience what? Remember a Maybe is just a union under the hood. And this also only happens with compound literals with inferred types. I am 99% sure this is your bug.

from odin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.