Merge pull request #20952 from dkorpel/merge-stable

Merge stable
This commit is contained in:
Nicholas Wilson 2025-03-05 19:00:22 +08:00 committed by GitHub
commit ee6449ded0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 99 additions and 25 deletions

View file

@ -704,6 +704,12 @@ MATCH implicitConvTo(Expression e, Type t)
if (!tn.isConst() && !tn.isImmutable()) if (!tn.isConst() && !tn.isImmutable())
return MATCH.nomatch; return MATCH.nomatch;
m = MATCH.constant; m = MATCH.constant;
// After converting e.g. ubyte[] to const(ubyte)[], don't change
// to MATCH.convert, return MATCH.constant
// https://github.com/dlang/dmd/issues/20635
if (e.type.ty == t.ty && e.type.nextOf().ty == tn.ty)
return m;
} }
if (e.type != t && e.hexString && tn.isIntegral && (tn.size == e.sz || (!e.committed && (e.len % tn.size) == 0))) if (e.type != t && e.hexString && tn.isIntegral && (tn.size == e.sz || (!e.committed && (e.len % tn.size) == 0)))
{ {

View file

@ -4184,7 +4184,8 @@ private extern(C++) class AddMemberVisitor : Visitor
} }
// If using C tag/prototype/forward declaration rules // If using C tag/prototype/forward declaration rules
if (sc.inCfile && !dsym.isImport()) if (sc && sc.inCfile && !dsym.isImport())
// When merging master, replace with: if (sc && sc.inCfile && !dsym.isImport())
{ {
if (handleTagSymbols(*sc, dsym, s2, sds)) if (handleTagSymbols(*sc, dsym, s2, sds))
return; return;

View file

@ -1453,11 +1453,6 @@ private Expression resolveUFCSProperties(Scope* sc, Expression e1, Expression e2
auto arguments = new Expressions(1); auto arguments = new Expressions(1);
(*arguments)[0] = eleft; (*arguments)[0] = eleft;
e = new CallExp(loc, e, arguments); e = new CallExp(loc, e, arguments);
// https://issues.dlang.org/show_bug.cgi?id=24017
if (sc.debug_)
e.isCallExp().inDebugStatement = true;
e = e.expressionSemantic(sc); e = e.expressionSemantic(sc);
return e; return e;
} }
@ -13077,6 +13072,11 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
error(exp.loc, "compare not defined for complex operands"); error(exp.loc, "compare not defined for complex operands");
return setError(); return setError();
} }
else if (t1.isTypeFunction() || t2.isTypeFunction())
{
error(exp.loc, "comparison is not defined for function types");
return setError();
}
else if (t1.ty == Taarray || t2.ty == Taarray) else if (t1.ty == Taarray || t2.ty == Taarray)
{ {
error(exp.loc, "`%s` is not defined for associative arrays", EXPtoString(exp.op).ptr); error(exp.loc, "`%s` is not defined for associative arrays", EXPtoString(exp.op).ptr);
@ -13382,6 +13382,12 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return; return;
} }
if (t1.isTypeFunction() || t2.isTypeFunction())
{
error(exp.loc, "operator `==` is not defined for function types");
return setError();
}
if (auto tv = t1.isTypeVector()) if (auto tv = t1.isTypeVector())
exp.type = tv.toBooleanVector(); exp.type = tv.toBooleanVector();
@ -13438,6 +13444,12 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
if (exp.e2.op == EXP.call) if (exp.e2.op == EXP.call)
exp.e2 = (cast(CallExp)exp.e2).addDtorHook(sc); exp.e2 = (cast(CallExp)exp.e2).addDtorHook(sc);
if (exp.e1.type.isTypeFunction() || exp.e2.type.isTypeFunction())
{
error(exp.loc, "operator `is` is not defined for function types");
return setError();
}
if (exp.e1.type.toBasetype().ty == Tsarray || if (exp.e1.type.toBasetype().ty == Tsarray ||
exp.e2.type.toBasetype().ty == Tsarray) exp.e2.type.toBasetype().ty == Tsarray)
deprecation(exp.loc, "identity comparison of static arrays " deprecation(exp.loc, "identity comparison of static arrays "

View file

@ -567,7 +567,7 @@ private bool pragmaMsgSemantic(Loc loc, Scope* sc, Expressions* args)
return false; return false;
buf.writestring("\n"); buf.writestring("\n");
fprintf(stderr, buf.extractChars); fprintf(stderr, "%s", buf.extractChars);
return true; return true;
} }

View file

@ -135,7 +135,16 @@ private Expression checkAssignmentAsCondition(Expression e, Scope* sc)
return e; return e;
} }
// Performs semantic analysis in Statement AST nodes /**
* Performs semantic analysis in Statement AST nodes
*
* Params:
* s = statement to perform semantic analysis on
* sc = scope in which statement resides
*
* Returns: statement `s` after semantic analysis.
* Can be `null`, for example with `pragma(msg, "")`
*/
Statement statementSemantic(Statement s, Scope* sc) Statement statementSemantic(Statement s, Scope* sc)
{ {
import dmd.compiler; import dmd.compiler;
@ -3488,6 +3497,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
sc = sc.push(); sc = sc.push();
sc.debug_ = true; sc.debug_ = true;
ds.statement = ds.statement.statementSemantic(sc); ds.statement = ds.statement.statementSemantic(sc);
debugThrowWalker(ds.statement);
sc.pop(); sc.pop();
} }
result = ds.statement; result = ds.statement;
@ -4760,7 +4770,6 @@ private Statements* flatten(Statement statement, Scope* sc)
if (dc) if (dc)
{ {
s = new DebugStatement(cs.loc, cs.ifbody); s = new DebugStatement(cs.loc, cs.ifbody);
debugThrowWalker(cs.ifbody);
} }
else else
s = cs.ifbody; s = cs.ifbody;
@ -4932,7 +4941,8 @@ Params:
*/ */
private void debugThrowWalker(Statement s) private void debugThrowWalker(Statement s)
{ {
if (!s)
return;
extern(C++) final class DebugWalker : SemanticTimeTransitiveVisitor extern(C++) final class DebugWalker : SemanticTimeTransitiveVisitor
{ {
alias visit = SemanticTimeTransitiveVisitor.visit; alias visit = SemanticTimeTransitiveVisitor.visit;

View file

@ -13,6 +13,7 @@ print dstring
foo_str foo_str
foo_wstr foo_wstr
foo_dstr foo_dstr
X%nY
--- ---
*/ */
@ -33,4 +34,7 @@ void main()
pragma(msg, a); pragma(msg, a);
pragma(msg, b); pragma(msg, b);
pragma(msg, c); pragma(msg, c);
// https://github.com/dlang/dmd/issues/20894
pragma(msg, "X%nY");
} }

View file

@ -85,3 +85,17 @@ void test6() nothrow
() {throw new Exception("");}(); () {throw new Exception("");}();
} }
} }
void writeln() {}
void writeln(string) {}
void test7() nothrow
{
debug writeln("Hello"); // https://issues.dlang.org/show_bug.cgi?id=24017
debug "Hello".writeln;
debug writeln = "Hello"; // https://github.com/dlang/dmd/issues/20719
debug writeln;
// https://github.com/dlang/dmd/pull/20720#issuecomment-2596892489
debug pragma(msg, ""); // Came up as segfault, pragma statement became null after semantic
}

View file

@ -1,11 +0,0 @@
// https://issues.dlang.org/show_bug.cgi?id=24017
// REQUIRED_ARGS: -debug
void writeln(string) {}
void main() nothrow
{
debug writeln("Hello");
debug "Hello".writeln;
}

View file

@ -2,10 +2,13 @@
/* /*
TEST_OUTPUT: TEST_OUTPUT:
--- ---
fail_compilation/fail22151.d(14): Error: function `test` is not an lvalue and cannot be modified fail_compilation/fail22151.d(17): Error: function `test` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(15): Error: function `test2` is not an lvalue and cannot be modified fail_compilation/fail22151.d(18): Error: function `test2` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(18): Error: function pointed to by `fp` is not an lvalue and cannot be modified fail_compilation/fail22151.d(21): Error: function pointed to by `fp` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(21): Error: function pointed to by `ff` is not an lvalue and cannot be modified fail_compilation/fail22151.d(24): Error: function pointed to by `ff` is not an lvalue and cannot be modified
fail_compilation/fail22151.d(27): Error: operator `==` is not defined for function types
fail_compilation/fail22151.d(28): Error: operator `is` is not defined for function types
fail_compilation/fail22151.d(29): Error: comparison is not defined for function types
--- ---
*/ */
@ -19,6 +22,11 @@ void test()
auto ff = &test2; auto ff = &test2;
*ff = *&test2; *ff = *&test2;
// https://github.com/dlang/dmd/issues/18281
const c = *fp == *fp;
const d = *fp is *fp;
const e = *fp < *fp;
} }
void test2(); void test2();

View file

@ -0,0 +1,11 @@
/**
TEST_OUTPUT:
---
fail_compilation/test20859.d(8): Error: variable `test20859.ICE.__vtbl` conflicts with variable `test20859.ICE.__vtbl` at fail_compilation/test20859.d(10)
---
*/
class ICE
{
void **__vtbl;
}

View file

@ -277,8 +277,16 @@ void testHexstring()
static immutable ulong[] z0 = cast(immutable ulong[]) x"1111 1111 1111 1111 0000 000F 0000 0000"; static immutable ulong[] z0 = cast(immutable ulong[]) x"1111 1111 1111 1111 0000 000F 0000 0000";
static immutable ulong[] z1 = [0x1111_1111_1111_1111, 0x0000_000E_0000_0000]; static immutable ulong[] z1 = [0x1111_1111_1111_1111, 0x0000_000E_0000_0000];
static assert(z0 !is z1); static assert(z0 !is z1);
// https://github.com/dlang/dmd/issues/20635
f20635(cast(ubyte[]) x"00");
f20635(cast(const ubyte[]) x"00");
f20635(cast(immutable ubyte[]) x"00");
} }
void f20635(const ubyte[] value){}
void f20635(const string value){}
/***************************************************/ /***************************************************/
int main() int main()

View file

@ -240,6 +240,16 @@ void test8()
/*********************************************************/ /*********************************************************/
// https://github.com/dlang/dmd/issues/20907
struct Bar { enum bar = 1; }
void foo(A)(A[], A[1 << A.bar]) {}
void test20907()
{
foo((Bar[]).init, (Bar[2]).init);
}
/*********************************************************/
int main() int main()
{ {
test1(); test1();
@ -250,6 +260,7 @@ int main()
test6(); test6();
test7(); test7();
test8(); test8();
test20907();
printf("Success\n"); printf("Success\n");
return 0; return 0;