Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix issue 8128 - allow unittest blocks in interfaces. #960

Merged
merged 3 commits into from

4 participants

src/func.c
@@ -358,7 +358,7 @@ void FuncDeclaration::semantic(Scope *sc)
#endif
isDtorDeclaration() ||
isInvariantDeclaration() ||
- isUnitTestDeclaration() || isNewDeclaration() || isDelete())
+ isNewDeclaration() || isDelete())
error("constructors, destructors, postblits, invariants, unittests, new and delete functions are not allowed in interface %s", id->toChars());
@yebblies Collaborator
yebblies added a note

Might want to fix the error message too.

@alexrp
alexrp added a note

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@9rnsr
Collaborator

You should add test for the feature.

@alexrp

Rebased and added test.

@alexrp

Poking this to make the auto tester run it on OS X machines.

@andralex
Owner

This is great in conjunction with the factory pattern. It's also consistent with the "turtles all the way down" principle. Approved. Please review implementation and merge.

On the topic: we should allow non-final method definitions in interfaces. C# added that feature recently amid feedback from its users.

@9rnsr
Collaborator

@alexp , test/runnable/interface.d is not good place for the test, because it doesn't have REQUIRED_ARGS: -unittest.

You should write following test in test/runnable/test19.d.

/* ================================ */
// 8128

int flag8128 = 0;

interface I8128
{
    unittest
    {
        printf("utest, flag8128 = %d\n", flag8128);
        flag8128 = 1;
    }
}

void test8128()
{
    printf("main, flag8128 = %d\n", flag8128);
    assert(flag8128 == 1);
}

/* ================================ */
@9rnsr
Collaborator

Implementation is good. After fixing test, I'll merge this.

@andralex
Owner

Great! What do you think about deprecated with message?

@9rnsr
Collaborator

It sounds not so bad. I'll review it later.

@alexrp

Rebased with requested changes.

@9rnsr 9rnsr merged commit 1d70dce into D-Programming-Language:master
@9rnsr
Collaborator

Merged. Thanks for your contribution.

@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 19, 2012
  1. @alexrp

    Fix issue 8128 - allow unittest blocks in interfaces.

    alexrp authored alexrp committed
  2. @alexrp

    Also fix error message.

    alexrp authored
Commits on Sep 30, 2012
  1. @alexrp
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 2 deletions.
  1. +2 −2 src/func.c
  2. +17 −0 test/runnable/test19.d
View
4 src/func.c
@@ -353,8 +353,8 @@ void FuncDeclaration::semantic(Scope *sc)
#endif
isDtorDeclaration() ||
isInvariantDeclaration() ||
- isUnitTestDeclaration() || isNewDeclaration() || isDelete())
- error("constructors, destructors, postblits, invariants, unittests, new and delete functions are not allowed in interface %s", id->toChars());
+ isNewDeclaration() || isDelete())
+ error("constructors, destructors, postblits, invariants, new and delete functions are not allowed in interface %s", id->toChars());
if (fbody && isVirtual())
error("function body is not abstract in interface %s", id->toChars());
}
View
17 test/runnable/test19.d
@@ -401,7 +401,24 @@ void test20()
}
/* ================================ */
+// 8128
+int flag8128 = 0;
+
+interface I8128
+{
+ unittest
+ {
+ printf("utest, flag8128 = %d\n", flag8128);
+ flag8128 = 1;
+ }
+}
+
+void test8128()
+{
+ printf("main, flag8128 = %d\n", flag8128);
+ assert(flag8128 == 1);
+}
int main()
{
Something went wrong with that request. Please try again.