diff --git a/build.sh b/build.sh index d5d6de1..80421bd 100755 --- a/build.sh +++ b/build.sh @@ -61,7 +61,7 @@ FLAGS="$FLAGS -file-id-output build/fileIdPins" # see generation.md NEXT=compiler$(($($NEAT -print-generation) + 1)) $NEAT $FLAGS -backend=c -macro-backend=c -next-generation -P$NEXT:src -j src/main.nt \ - -o build/neat_stage1 + -version=firstpass -o build/neat_stage1 cat build/fileIdPins -< build/neat.ini -syspackage compiler:src -running-compiler-version=$TAG diff --git a/src/neat/statements.nt b/src/neat/statements.nt index 9195794..2f46f0f 100644 --- a/src/neat/statements.nt +++ b/src/neat/statements.nt @@ -394,10 +394,13 @@ Statement sequence(Statement left, nullable Statement right) } Statement sequence2(nullable Statement first, Statement second) { - // TODO this has a lifetime bug - // return first?.(sequence(that, second)) else second; - if (auto first = first) return sequence(first, second); - return second; + // TODO remove + version (firstpass) { + if (auto first = first) return first.(sequence(that, second)); + return second; + } else { + return first?.(sequence(that, second)) else second; + } } class StatementExpression : Expression diff --git a/src/neat/ternary.nt b/src/neat/ternary.nt index 5e1b6e3..7463c41 100644 --- a/src/neat/ternary.nt +++ b/src/neat/ternary.nt @@ -55,9 +55,10 @@ class ASTTernaryIf : ASTSymbol * else { result = else_; } */ auto lifetimeThen = then if elseIsBottom else then.take(context, __RANGE__)?; + auto lifetimeElse = else_ if elseIsBottom else else_.take(context, __RANGE__)?; auto thenConvert = expectImplicitConvertTo( context, lifetimeThen, mergedType, this.locRange)?; - auto elseConvert = expectImplicitConvertTo(context, else_, mergedType, this.locRange)?; + auto elseConvert = expectImplicitConvertTo(context, lifetimeElse, mergedType, this.locRange)?; // If else is bottom, we can just use the lifetime of `then` directly. auto lifetime = then.info.lifetime if elseIsBottom else Lifetime.gifted; auto result = new PairedTemporary(mergedType, lifetime, context.getUniqueId); diff --git a/test/runnable/lifetime.nt b/test/runnable/lifetime.nt index b3e95b1..3433330 100644 --- a/test/runnable/lifetime.nt +++ b/test/runnable/lifetime.nt @@ -601,9 +601,9 @@ void test_either_replace() assert(trace == "-S0 -T0 -U0"); } -void test_else_prop() +void test_short_ternary() { - dbg("- else property"); + dbg("- short ternary"); { string trace; { @@ -619,6 +619,16 @@ void test_else_prop() test? else new C(S("S", &trace, 0)); assert(trace == "+S1 -S0 -S1"); } + { + string trace; + { + (int | :else) test = :else; + auto c = new C(S("S", &trace, 0)); + test? else c; + assert(trace == "+S1 -S0"); + } + assert(trace == "+S1 -S0 -S1"); + } { string trace; (int | :else) test = 0; @@ -1189,7 +1199,7 @@ void main() test_class_member_ref; test_either_member; test_either_replace; - test_else_prop; + test_short_ternary; test_error_prop; test_array_cat; test_statement_expr;