Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify nested maps #778

Open
purpleidea opened this issue Nov 11, 2024 · 1 comment
Open

Unify nested maps #778

purpleidea opened this issue Nov 11, 2024 · 1 comment

Comments

@purpleidea
Copy link
Owner

Versions:

  • mgmt version (eg: mgmt --version):

Current git master of: 43bd847

  • golang version (eg: go version):

go version go1.22.7 linux/amd64

Description:

I'd expect the following code to unify automatically, but it does not. If we specify the type (as shown) then it works.

$bigmap = {
	"key1" => {
		"foo" => "thing1a",
		"bar" => "thing1b",
	},
	"key2" => {
		"foo" => "thing2a",	# pull out this!
		"bar" => "thing2b",
	},
}

$key = "key2"

#$inner map{str: str} = $bigmap[$key] # does unify with the type hint!
$inner = $bigmap[$key] # doesn't unify!

print "debug" {
	msg => $inner["foo"],
}

You can easily run this with:

./mgmt run --tmp-prefix lang unify-bug-or-not.mcl

I also tried applying this patch in case, but it did not change the result:

diff --git lang/ast/structs.go lang/ast/structs.go
index a8b844bc6..f0d80447e 100644
--- lang/ast/structs.go
+++ lang/ast/structs.go
@@ -7689,6 +7689,15 @@ func (obj *ExprFunc) Infer() (*types.Type, []*interfaces.UnificationInvariant, e
                }
                invariants = append(invariants, invars...)
 
+               // XXX >>>
+               invarFoo := &interfaces.UnificationInvariant{
+                       Expr:   obj.params[i],
+                       Expect: typArg,
+                       Actual: typArg,
+               }
+               invariants = append(invariants, invarFoo)
+               // <<< XXX
+
                m[arg.Name] = typArg
                ord = append(ord, arg.Name)
        }

@purpleidea
Copy link
Owner Author

Btw, the error we get is:

cli parse error: could not unify types: expr: call:_lookup(var(bigmap), var(key)) is ambiguous: ?1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant