carbon-language / carbon-lang

Carbon Language's main repository: documents, design, implementation, and related tools. (NOTE: Carbon Language is experimental; see README)
https://github.com/carbon-language/carbon-lang/blob/trunk/README.md
Other
32.31k stars 1.48k forks source link

Treat constants with symbolic type as being symbolic. #4082

Closed zygoloid closed 4 days ago

zygoloid commented 5 days ago

When constant evaluation produces a known non-symbolic value, treat the result as a symbolic constant anyway if the type of the value is symbolic.

We don't yet have many ways to produce a constant that has a known value but a symbolic type. The added test case is one such way: an array [T; 0] initialized from () is a symbolic constant only because its type is symbolic -- we know its value is always (). More ways to form such constants will be appearing soon as we start to support generics: for example, a method of a generic class has a symbolic type but a known constant value of {}.

When substituting into a symbolic constant, also substitute into its type.