]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Report error in real literal if exponent has no digits
author星外之神 <wszqkzqk@qq.com>
Tue, 25 Oct 2022 13:02:32 +0000 (21:02 +0800)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 26 Oct 2022 05:14:00 +0000 (07:14 +0200)
tests/Makefile.am
tests/semantic/realliteral-exponent-has-no-digits.test [new file with mode: 0644]
tests/semantic/realliteral-exponent-has-no-digits2.test [new file with mode: 0644]
tests/semantic/realliteral-exponent-has-no-digits3.test [new file with mode: 0644]
vala/valarealliteral.vala

index 6a2acf56c5ff5f9847b8b5bc5d799250c3c8a41c..10ff6183ff43b3e671e87ee975625ba1372b21a3 100644 (file)
@@ -1243,6 +1243,9 @@ TESTS = \
        semantic/property-too-few-type-arguments.test \
        semantic/property-too-many-type-arguments.test \
        semantic/property-void.test \
+       semantic/realliteral-exponent-has-no-digits.test \
+       semantic/realliteral-exponent-has-no-digits2.test \
+       semantic/realliteral-exponent-has-no-digits3.test \
        semantic/reference-transfer-not-supported.test \
        semantic/reference-transfer-unavailable.test \
        semantic/return-in-nonvoid.test \
diff --git a/tests/semantic/realliteral-exponent-has-no-digits.test b/tests/semantic/realliteral-exponent-has-no-digits.test
new file mode 100644 (file)
index 0000000..fbe418a
--- /dev/null
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+       double foo = 18.93e;
+}
diff --git a/tests/semantic/realliteral-exponent-has-no-digits2.test b/tests/semantic/realliteral-exponent-has-no-digits2.test
new file mode 100644 (file)
index 0000000..b0d48fa
--- /dev/null
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+       double foo = 20.03e+;
+}
diff --git a/tests/semantic/realliteral-exponent-has-no-digits3.test b/tests/semantic/realliteral-exponent-has-no-digits3.test
new file mode 100644 (file)
index 0000000..0256423
--- /dev/null
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+       double foo = 7.11e-;
+}
index 2924cd764733cba4d6067ac73937b33100ba0f6f..c992fba6fd10433017bdaf3b8b75caa3c635180a 100644 (file)
@@ -71,6 +71,11 @@ public class Vala.RealLiteral : Literal {
                        type_name = "double";
                }
 
+               if (value.has_suffix ("e") || value.has_suffix ("+") || value.has_suffix ("-")) {
+                       Report.error (source_reference, "exponent has no digits");
+                       error = true;
+               }
+
                var st = (Struct) context.root.scope.lookup (type_name);
                // ensure attributes are already processed
                st.check (context);