Skip to content

Loading…

Issue 9312 - With statement diagnostic is wrong #1479

Merged
merged 1 commit into from

2 participants

@ghost

http://d.puremagic.com/issues/show_bug.cgi?id=9312

It only lists class and struct instances as possible expressions, but there are many more: class and struct types, template instances, enumerations, modules, etc. To avoid listing all possible types it's best to just state the type which can't be used.

@ghost ghost closed this
@ghost

You know it can actually be many things: class instance, struct instance, class or struct type, enumeration type, template instance, module declaration.

I think it might be simpler if we just said with expression cannot be of type xyz.

@ghost ghost reopened this
@9rnsr
D Programming Language member

I think we can summarize the set of class, struct, union, and interface to 'aggregate'.
How about with expressions must be aggregate objects, not xxx?

@ghost

@9rnsr: Sure, that could work. Done.

@9rnsr
D Programming Language member

LGTM.

@9rnsr 9rnsr merged commit 6cfa082 into D-Programming-Language:master

1 check passed

Details default Pass: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 14, 2013
  1. @AndrejMitrovic
Showing with 14 additions and 1 deletion.
  1. +1 −1 src/statement.c
  2. +13 −0 test/fail_compilation/diag9312.d
View
2 src/statement.c
@@ -4538,7 +4538,7 @@ Statement *WithStatement::semantic(Scope *sc)
sym->parent = sc->scopesym;
}
else
- { error("with expressions must be class objects, not '%s'", exp->type->toChars());
+ { error("with expressions must be aggregate types, not '%s'", exp->type->toChars());
return NULL;
}
}
View
13 test/fail_compilation/diag9312.d
@@ -0,0 +1,13 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/diag9312.d(10): Error: with expressions must be aggregate types, not 'int'
+---
+*/
+
+void main()
+{
+ with (1)
+ {
+ }
+}
Something went wrong with that request. Please try again.