The purpose of ensure_can_take_address() is to check that making a pointer to something (as in &foo) makes sense. But unlike you would expect, it isn't used just in the &foo syntax. Several other things, such as foo = bar and &foo.bar, also need a pointer to foo. The ensure_can_take_address() function handles them all.
This means that it is important for ensure_can_take_address() to generate good error messages. The error message logic is also a bit complicated, and previously behaved wrong in some corner cases: Foo{}.x++ resulted in an error message saying you are trying to increment a newly created instance. It now says that you are trying to increment a field of a newly created instance.
The purpose of
ensure_can_take_address()
is to check that making a pointer to something (as in&foo
) makes sense. But unlike you would expect, it isn't used just in the&foo
syntax. Several other things, such asfoo = bar
and&foo.bar
, also need a pointer tofoo
. Theensure_can_take_address()
function handles them all.This means that it is important for
ensure_can_take_address()
to generate good error messages. The error message logic is also a bit complicated, and previously behaved wrong in some corner cases:Foo{}.x++
resulted in an error message saying you are trying to increment a newly created instance. It now says that you are trying to increment a field of a newly created instance.