Cesium
Cesium copied to clipboard
Const analysis
As of now, Cesium ignores const keyword almost everywhere.
It should start analyzing const and embed this info into the type (and possibly even into CLI metadata).
See TODO[#91] in the code for possible places where this analysis can be added.
I think we have const in bunch of places. Unless we want to have specific list, we can close this.
I believe that const check should be a part (or a stage, if you will) of the type check algorithm; the problem being we don't have it as a separate entity (yet!).
But you are right in that we should start with some concrete examples. So, let's start with this:
int main() {
const int *x = 0;
int *y = x;
y[0] = 0;
}
This should not compile, yet it happily compiles in Cesium.
A quick unit test, if it helps:
Index: Cesium.CodeGen.Tests/CodeGenArrayTests.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Cesium.CodeGen.Tests/CodeGenArrayTests.cs b/Cesium.CodeGen.Tests/CodeGenArrayTests.cs
--- a/Cesium.CodeGen.Tests/CodeGenArrayTests.cs (revision Staged)
+++ b/Cesium.CodeGen.Tests/CodeGenArrayTests.cs (date 1731013354166)
@@ -14,6 +14,13 @@
return VerifyMethods(moduleType);
}
+ [Fact]
+ public Task MyCheck1() => DoTest(@"int main() {
+ const int *x = 0;
+ int *y = x;
+ y[0] = 0;
+}");
+
[Fact]
public Task ArrayAssignment() => DoTest(@"int main() {
int a[10];