Skip to content

Commit 468aaf4

Browse files
committed
[error] Improve diagnostic for concatenation to a string reference.
Fix #225
1 parent a6c7aa6 commit 468aaf4

5 files changed

Lines changed: 17 additions & 0 deletions

File tree

Sema.fu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ public class FuSema
11441144
CheckLValue(left);
11451145
if (left.Type.Id == FuId.StringStorageType)
11461146
Coerce(right, this.Host.Program.System.StringPtrType);
1147+
else if (left.Type.Id == FuId.StringPtrType)
1148+
ReportError(left, $"'{left}' is 'string', concatenation requires 'string()'");
11471149
else {
11481150
Coerce(left, this.Host.Program.System.DoubleType);
11491151
Coerce(right, left.Type);

libfut.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5715,6 +5715,8 @@ std::shared_ptr<FuExpr> FuSema::visitBinaryExpr(std::shared_ptr<FuBinaryExpr> ex
57155715
checkLValue(left.get());
57165716
if (left->type->id == FuId::stringStorageType)
57175717
coerce(right.get(), this->host->program->system->stringPtrType.get());
5718+
else if (left->type->id == FuId::stringPtrType)
5719+
reportError(left.get(), std::format("'{}' is 'string', concatenation requires 'string()'", left->toString()));
57185720
else {
57195721
coerce(left.get(), this->host->program->system->doubleType.get());
57205722
coerce(right.get(), left->type.get());

libfut.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5848,6 +5848,8 @@ FuExpr VisitBinaryExpr(FuBinaryExpr expr)
58485848
CheckLValue(left);
58495849
if (left.Type.Id == FuId.StringStorageType)
58505850
Coerce(right, this.Host.Program.System.StringPtrType);
5851+
else if (left.Type.Id == FuId.StringPtrType)
5852+
ReportError(left, $"'{left}' is 'string', concatenation requires 'string()'");
58515853
else {
58525854
Coerce(left, this.Host.Program.System.DoubleType);
58535855
Coerce(right, left.Type);

libfut.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6172,6 +6172,8 @@ export class FuSema
61726172
this.#checkLValue(left);
61736173
if (left.type.id == FuId.STRING_STORAGE_TYPE)
61746174
this.#coerce(right, this.#host.program.system.stringPtrType);
6175+
else if (left.type.id == FuId.STRING_PTR_TYPE)
6176+
this.#reportError(left, `'${left}' is 'string', concatenation requires 'string()'`);
61756177
else {
61766178
this.#coerce(left, this.#host.program.system.doubleType);
61776179
this.#coerce(right, left.type);

test/error/OpAddAssignStringPtr.fu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Test
2+
{
3+
public static bool Run()
4+
{
5+
string s = "";
6+
s += "foo"; //ERROR: 's' is 'string', concatenation requires 'string()'
7+
return true;
8+
}
9+
}

0 commit comments

Comments
 (0)