From 33260eb537ac9398f60ff356f14d5d63841cfd59 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Tue, 29 Dec 2020 16:20:49 +0100 Subject: [PATCH] Remove complex and imaginary types from language in Edition v2024 --- compiler/src/dmd/lexer.d | 20 +++++++++++++++- compiler/src/dmd/parse.d | 1 + compiler/test/compilable/edition_complex.d | 23 ++++++++++++++++++ .../test/fail_compilation/edition_complex.d | 24 +++++++++++++++++++ .../test/fail_compilation/edition_complex2.d | 16 +++++++++++++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 compiler/test/compilable/edition_complex.d create mode 100644 compiler/test/fail_compilation/edition_complex.d create mode 100644 compiler/test/fail_compilation/edition_complex2.d diff --git a/compiler/src/dmd/lexer.d b/compiler/src/dmd/lexer.d index b8a4223f884d..e656e9f02080 100644 --- a/compiler/src/dmd/lexer.d +++ b/compiler/src/dmd/lexer.d @@ -17,6 +17,7 @@ import core.stdc.ctype; import core.stdc.stdio; import core.stdc.string; +import dmd.astenums : Edition; import dmd.entity; import dmd.errorsink; import dmd.id; @@ -90,6 +91,7 @@ class Lexer ErrorSink eSink; /// send error messages through this interface CompileEnv compileEnv; /// environment + Edition edition; /// language edition that is in force private { @@ -838,6 +840,22 @@ class Lexer p++; } } + if (this.edition >= Edition.v2024) + { + switch (t.value) + { + case TOK.imaginary32: + case TOK.imaginary64: + case TOK.imaginary80: + case TOK.complex32: + case TOK.complex64: + case TOK.complex80: + t.value = TOK.identifier; + break; + default: + break; + } + } //printf("t.value = %d\n",t.value); return; } @@ -3100,7 +3118,7 @@ class Lexer break; } - if ((*p == 'i' || *p == 'I') && !Ccompile) + if ((*p == 'i' || *p == 'I') && !Ccompile && this.edition < Edition.v2024) { if (*p == 'I') error("use 'i' suffix instead of 'I'"); diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index a459b89e520c..821ade3aeb4f 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -239,6 +239,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer if (id.ident == Id.__edition_latest_do_not_use) { mod.edition = Edition.latest; + this.edition = Edition.latest; continue; } diff --git a/compiler/test/compilable/edition_complex.d b/compiler/test/compilable/edition_complex.d new file mode 100644 index 000000000000..68f4e25dcc0b --- /dev/null +++ b/compiler/test/compilable/edition_complex.d @@ -0,0 +1,23 @@ +@__edition_latest_do_not_use +module edition_complex; + +struct cfloat +{ + float re; + ifloat im; +} +alias ifloat = float; + +struct cdouble +{ + double re; + idouble im; +} +alias idouble = double; + +struct creal +{ + real re; + ireal im; +} +alias ireal = real; diff --git a/compiler/test/fail_compilation/edition_complex.d b/compiler/test/fail_compilation/edition_complex.d new file mode 100644 index 000000000000..e7812f223ed6 --- /dev/null +++ b/compiler/test/fail_compilation/edition_complex.d @@ -0,0 +1,24 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/edition_complex.d(3): Error: undefined identifier `ifloat` +fail_compilation/edition_complex.d(4): Error: undefined identifier `cfloat` +fail_compilation/edition_complex.d(5): Error: undefined identifier `idouble` +fail_compilation/edition_complex.d(6): Error: undefined identifier `cdouble` +fail_compilation/edition_complex.d(7): Error: undefined identifier `ireal` +fail_compilation/edition_complex.d(8): Error: undefined identifier `creal` +--- + */ +@__edition_latest_do_not_use +module edition_complex; + +#line 1 +void main() +{ + ifloat fi; + cfloat fc; + idouble di; + cdouble dc; + ireal ri; + creal rc; +} diff --git a/compiler/test/fail_compilation/edition_complex2.d b/compiler/test/fail_compilation/edition_complex2.d new file mode 100644 index 000000000000..5c7c4d39ebe8 --- /dev/null +++ b/compiler/test/fail_compilation/edition_complex2.d @@ -0,0 +1,16 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/edition_complex2.d(3): Error: semicolon expected following auto declaration, not `i` +fail_compilation/edition_complex2.d(4): Error: semicolon expected following auto declaration, not `i` +--- + */ +@__edition_latest_do_not_use +module edition_complex2; + +#line 1 +void main() +{ + auto cv = 1.0+0.0i; + auto iv = 1.0i; +}