Skip to content
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

Remove complex and imaginary types from language in Edition v2024 #12069

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion compiler/src/dmd/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'");
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 23 additions & 0 deletions compiler/test/compilable/edition_complex.d
Original file line number Diff line number Diff line change
@@ -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;
24 changes: 24 additions & 0 deletions compiler/test/fail_compilation/edition_complex.d
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 16 additions & 0 deletions compiler/test/fail_compilation/edition_complex2.d
Original file line number Diff line number Diff line change
@@ -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;
}
Loading