@@ -3150,7 +3150,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
3150
3150
void visitWith (WithStatement ws)
3151
3151
{
3152
3152
/* https://dlang.org/spec/statement.html#with-statement
3153
- */
3153
+ */
3154
3154
3155
3155
ScopeDsymbol sym;
3156
3156
Initializer _init;
@@ -3160,8 +3160,10 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
3160
3160
ws.exp = resolveProperties(sc, ws.exp);
3161
3161
ws.exp = ws.exp.optimize(WANTvalue);
3162
3162
ws.exp = checkGC(sc, ws.exp);
3163
+
3163
3164
if (ws.exp.op == EXP .error)
3164
3165
return setError ();
3166
+
3165
3167
if (ws.exp.op == EXP .scope_)
3166
3168
{
3167
3169
sym = new WithScopeSymbol(ws);
@@ -3183,19 +3185,19 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
3183
3185
else
3184
3186
{
3185
3187
Type texp = ws.exp.type;
3186
- Type t = texp.toBasetype();
3188
+ if (! texp)
3189
+ {
3190
+ error(ws.loc, " Expression has no type." );
3191
+ return setError ();
3192
+ }
3187
3193
3188
- Expression olde = ws.exp ;
3189
- if (t.ty == Tpointer )
3194
+ Type t = texp.toBasetype() ;
3195
+ if (! t )
3190
3196
{
3191
- ws.exp = new PtrExp(ws.loc, ws.exp);
3192
- ws.exp = ws.exp.expressionSemantic(sc);
3193
- texp = ws.exp.type;
3194
- t = texp.toBasetype();
3197
+ error(ws.loc, " Unable to resolve base type." );
3198
+ return setError ();
3195
3199
}
3196
3200
3197
- assert (t);
3198
- t = t.toBasetype();
3199
3201
if (t.isClassHandle())
3200
3202
{
3201
3203
_init = new ExpInitializer(ws.loc, ws.exp);
@@ -3212,14 +3214,14 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
3212
3214
if (! ws.exp.isLvalue())
3213
3215
{
3214
3216
/* Re-write to
3215
- * {
3216
- * auto __withtmp = exp
3217
- * with(__withtmp)
3218
- * {
3219
- * ...
3220
- * }
3221
- * }
3222
- */
3217
+ * {
3218
+ * auto __withtmp = exp
3219
+ * with(__withtmp)
3220
+ * {
3221
+ * ...
3222
+ * }
3223
+ * }
3224
+ */
3223
3225
auto tmp = copyToTemp(0 , " __withtmp" , ws.exp);
3224
3226
tmp.dsymbolSemantic(sc);
3225
3227
auto es = new ExpStatement(ws.loc, tmp);
@@ -3233,9 +3235,9 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
3233
3235
ws.wthis = new VarDeclaration(ws.loc, e.type, Id.withSym, _init);
3234
3236
ws.wthis.storage_class |= STC .temp;
3235
3237
ws.wthis.dsymbolSemantic(sc);
3238
+
3236
3239
sym = new WithScopeSymbol(ws);
3237
- // Need to set the scope to make use of resolveAliasThis
3238
- sym.setScope(sc);
3240
+ sym.setScope(sc); // Enable resolveAliasThis
3239
3241
sym.parent = sc.scopesym;
3240
3242
sym.endlinnum = ws.endloc.linnum;
3241
3243
}
@@ -3248,7 +3250,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
3248
3250
}
3249
3251
else
3250
3252
{
3251
- error(ws.loc, " `with` expression types must be enums or aggregates or pointers to them , not `%s`" , olde.type .toChars());
3253
+ error(ws.loc, " `with` expression types must be enums, structs, or classes , not `%s`" , t .toChars());
3252
3254
return setError ();
3253
3255
}
3254
3256
}
@@ -3260,6 +3262,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
3260
3262
sc.insert(sym);
3261
3263
ws._body = ws._body.statementSemantic(sc);
3262
3264
sc.pop();
3265
+
3263
3266
if (ws._body && ws._body.isErrorStatement())
3264
3267
{
3265
3268
result = ws._body;
0 commit comments