-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Different behavior of CFE and the analyzer when constant depends on itself #59945
Comments
Summary: Analyzer detects self-referential constant |
cc @eernstg |
[Edit: The first version of this comment was not quite careful enough: It referred to #50383 which is about inference only, but the example in this issue does not rely on type inference. So I've basically rewritten this comment from scratch, reaching the opposite conclusion.] The language specification says that
The null safety feature specification does not modify or add anything to this rule, nor does any other accepted feature specification as far as I can see. It is not possible to refer to the value of a constant expression (or any expression) directly, it only occurs when that expression is the initializing expression in a constant variable declaration (or some subexpression thereof), such that we can refer to the value (or to some object that indirectly provides access to the value of that subexpression). This means that the above rule must give rise to an error at or in the same declarations as the following rule: 'It is a compile-time error if the value of a constant variable depends on the value of that same constant variable.' This means that it is not sufficient to have a syntactic cycle (in the example: The declaration of the variable This is not true when it comes to the example in this issue, because the value of This means that no error should be reported, and the analyzer should be adjusted accordingly. |
The following code produces an error in the analyzer but no issues in VM.
If to change the example to really invoke the constant then VM produces an error as well.
@eernstg @lrhn does in the first case the constant really depends on itself?
The text was updated successfully, but these errors were encountered: