Consider the following bb snippet: VAR_foo = "base" AAA = "foo" BBB = "${AAA}" VAR_${BBB} = "wrong" VAR_${AAA} = "right" VAR_foo expands to "wrong", which is very unintuitive. The problem happens in lib.bb.data.expandKeys() which expands variables alphabetically instead of definition order. It first renames VAR_${AAA} --> VAR_foo == "right" then renames VAR_${BBB} --> VAR_foo --> "wrong", instead of the other way around. You can reproduce this in OpenEmbedded by simply copying the 5-line bb snippet above into any recipe X, and run `bitbake -e X | grep '^VAR_foo='` .
Key expansion happens at a very specific time in the metadata when expandKeys is called. We don't dynamically expand keys. We also don't store the order of variable declaration as it makes very little sense to given the complexities of the overrides that are possible. I'd therefore argue that the current behaviour is correct and the only way bitbake can reasonably behave. Its clear and deterministic. I appreciate its not always 100% intuitive but I really can't see any other way the code can work, sorry.