Cesium icon indicating copy to clipboard operation
Cesium copied to clipboard

Const analysis

Open ForNeVeR opened this issue 3 years ago • 2 comments
trafficstars

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.

ForNeVeR avatar Feb 06 '22 16:02 ForNeVeR

I think we have const in bunch of places. Unless we want to have specific list, we can close this.

kant2002 avatar Nov 07 '24 13:11 kant2002

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];

ForNeVeR avatar Nov 07 '24 21:11 ForNeVeR