Skip to content

Commit

Permalink
Merge pull request #96 from rejectedsoftware/preview_fixes
Browse files Browse the repository at this point in the history
Fix compile errors with enabling DIP1000+DIP1021+in previews
  • Loading branch information
l-kramer authored Nov 7, 2024
2 parents 5634ce7 + bd6e6ea commit 9e24640
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion source/diet/defs.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ alias DietParserException = Exception;
Throws a `DietParserException` when called with a `false` condition at
run time.
*/
void enforcep(bool cond, lazy string text, Location loc) @safe
void enforcep(bool cond, lazy string text, ref const Location loc) @safe
{
if (__ctfe) {
import std.conv : to;
Expand Down
7 changes: 5 additions & 2 deletions source/diet/dom.d
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ NodeContent[] toNodeContent(in AttributeContent[] contents, Location loc)
/// Original text used to look up the translation (only set if translated)
string translationKey;


scope:

/// Constructs a new node.
this(Location loc = Location.init, string name = null,
Attribute[] attributes = null, NodeContent[] contents = null,
Expand Down Expand Up @@ -163,7 +166,7 @@ NodeContent[] toNodeContent(in AttributeContent[] contents, Location loc)
text = The text to append to the node
loc = Location in the source file
*/
void addText(string text, in Location loc)
void addText(string text, ref const Location loc)
{
if (contents.length && contents[$-1].kind == NodeContent.Kind.text && contents[$-1].loc == loc)
contents[$-1].value ~= text;
Expand All @@ -179,7 +182,7 @@ NodeContent[] toNodeContent(in AttributeContent[] contents, Location loc)

/** Determines if this node has any non-whitespace contents. */
bool hasNonWhitespaceContent()
const {
const scope {
import std.algorithm.searching : any;
return contents.any!(c => c.kind != NodeContent.Kind.text || c.value.ctstrip.length > 0);
}
Expand Down
4 changes: 2 additions & 2 deletions source/diet/html.d
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ private string getDoctypeMixin(ref CTX ctx, in Node node) @safe
return ctx.rawText(node.loc, "<"~doctype_str~">");
}

private string getCodeMixin(ref CTX ctx, const ref Node node, bool in_pre) @safe
private string getCodeMixin(ref CTX ctx, in Node node, bool in_pre) @safe
{
enforcep(node.attributes.length == 0, "Code lines may not have attributes.", node.loc);
enforcep(node.attribs == NodeAttribs.none, "Code lines may not specify translation or text block suffixes.", node.loc);
Expand All @@ -762,7 +762,7 @@ private string getCodeMixin(ref CTX ctx, const ref Node node, bool in_pre) @safe
return ret;
}

private string getCommentMixin(ref CTX ctx, const ref Node node) @safe
private string getCommentMixin(ref CTX ctx, in Node node) @safe
{
string ret = ctx.rawText(node.loc, "<!--");
ctx.depth++;
Expand Down
2 changes: 1 addition & 1 deletion source/diet/internal/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ string dstringEscape(in string str)
return ret;
}

string dstringUnescape(in string str)
string dstringUnescape(in return string str)
{
string ret;
size_t i, start = 0;
Expand Down
18 changes: 9 additions & 9 deletions source/diet/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ Document parseDiet(alias TR = identity)(const(InputFile)[] files)
string identity(string str, string context = null) nothrow @safe @nogc { return str; }


private string parseIdent(in string str, ref size_t start,
string breakChars, in Location loc)
private string parseIdent(return in string str, ref size_t start,
string breakChars, ref const Location loc)
@safe {
import std.array : back;
/* The stack is used to keep track of opening and
Expand Down Expand Up @@ -1347,7 +1347,7 @@ private string skipLine(ref string input, ref Location loc)
return ret;
}

private void parseAttributes(ref string input, ref size_t i, ref Node node, in Location loc)
private void parseAttributes(ref string input, ref size_t i, ref Node node, ref const Location loc)
@safe {
assert(i < input.length && input[i] == '(');
i++;
Expand Down Expand Up @@ -1391,7 +1391,7 @@ private void parseAttributes(ref string input, ref size_t i, ref Node node, in L
i++;
}

private void parseAttributeText(string input, ref AttributeContent[] dst, in Location loc)
private void parseAttributeText(string input, ref AttributeContent[] dst, ref const Location loc)
@safe {
size_t sidx = 0, idx = 0;

Expand Down Expand Up @@ -1428,7 +1428,7 @@ private void parseAttributeText(string input, ref AttributeContent[] dst, in Loc
input = input[idx .. $];
}

private string skipUntilClosingBrace(in string s, ref size_t idx, in Location loc)
private string skipUntilClosingBrace(return in string s, ref size_t idx, ref const Location loc)
@safe {
import std.algorithm.comparison : among;

Expand All @@ -1445,7 +1445,7 @@ private string skipUntilClosingBrace(in string s, ref size_t idx, in Location lo
assert(false);
}

private string skipUntilClosingBracket(in string s, ref size_t idx, in Location loc)
private string skipUntilClosingBracket(return in string s, ref size_t idx, ref const Location loc)
@safe {
import std.algorithm.comparison : among;

Expand Down Expand Up @@ -1502,7 +1502,7 @@ private string skipIndent(ref string input)

private bool isIndentChar(dchar ch) @safe { return ch == ' ' || ch == '\t'; }

private string skipAnyWhitespace(in string s, ref size_t idx)
private string skipAnyWhitespace(return in string s, ref size_t idx)
@safe {
import std.ascii : isWhite;

Expand Down Expand Up @@ -1570,7 +1570,7 @@ private bool isStringLiteral(string str)
assert(!isStringLiteral(`"name" value="#{name}"`));
}

private string skipExpression(in string s, ref size_t idx, in Location loc, bool multiline = false)
private string skipExpression(return in string s, ref size_t idx, ref const Location loc, bool multiline = false)
@safe {
string clamp_stack;
size_t start = idx;
Expand Down Expand Up @@ -1608,7 +1608,7 @@ private string skipExpression(in string s, ref size_t idx, in Location loc, bool
}


private string skipAttribString(in string s, ref size_t idx, char delimiter, in Location loc)
private string skipAttribString(return in string s, ref size_t idx, char delimiter, ref const Location loc)
@safe {
size_t start = idx;
while( idx < s.length ){
Expand Down
10 changes: 7 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -xe

COMPILER=$DC

DC=${DC%-*}
if [ "$DC" == "ldc" ]; then DC="ldc2"; fi

Expand All @@ -11,7 +13,9 @@ dub test
echo "Checing makepot for successful compilation..."
dub build :makepot

if [ "$DC" == "ldc2" ]; then
echo "Testing for DIP 1000 compatibility..."
DFLAGS="--preview=dip1000 --preview=dip25" dub build
if [ "$COMPILER" == "ldc-latest" ] || [ "$COMPILER" == "dmd-latest" ] ; then
echo "Testing for DIP 1000/1021/in compatibility..."
DFLAGS="-preview=dip1000 -preview=dip1021" dub build
DFLAGS="-preview=in" dub build
DFLAGS="-preview=dip1000 -preview=dip1021 -preview=in" dub build
fi

0 comments on commit 9e24640

Please sign in to comment.