Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 7050 - Safety error message should include full function names #1201

Merged
merged 1 commit into from Oct 27, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/expression.c
Expand Up @@ -1705,13 +1705,13 @@ void Expression::checkPurity(Scope *sc, FuncDeclaration *f)
{
if (outerfunc->setImpure())
error("pure function '%s' cannot call impure function '%s'",
outerfunc->toChars(), f->toChars());
outerfunc->toPrettyChars(), f->toPrettyChars());
}
}
#else
if (sc->func && sc->func->isPure() && !sc->intypeof && !f->isPure())
error("pure function '%s' cannot call impure function '%s'",
sc->func->toChars(), f->toChars());
sc->func->toPrettyChars(), f->toPrettyChars());
#endif
}

Expand Down Expand Up @@ -1805,8 +1805,13 @@ void Expression::checkSafety(Scope *sc, FuncDeclaration *f)
!f->isSafe() && !f->isTrusted())
{
if (sc->func->setUnsafe())
{
if (loc.linnum == 0) // e.g. implicitly generated dtor
loc = sc->func->loc;

error("safe function '%s' cannot call system function '%s'",
sc->func->toChars(), f->toChars());
sc->func->toPrettyChars(), f->toPrettyChars());
}
}
}
#endif
Expand Down Expand Up @@ -8321,12 +8326,12 @@ Expression *CallExp::semantic(Scope *sc)
if (sc->func && !tf->purity && !(sc->flags & SCOPEdebug))
{
if (sc->func->setImpure())
error("pure function '%s' cannot call impure %s '%s'", sc->func->toChars(), p, e1->toChars());
error("pure function '%s' cannot call impure %s '%s'", sc->func->toPrettyChars(), p, e1->toChars());
}
if (sc->func && tf->trust <= TRUSTsystem)
{
if (sc->func->setUnsafe())
error("safe function '%s' cannot call system %s '%s'", sc->func->toChars(), p, e1->toChars());
error("safe function '%s' cannot call system %s '%s'", sc->func->toPrettyChars(), p, e1->toChars());
}

if (!tf->callMatch(NULL, arguments))
Expand Down
14 changes: 14 additions & 0 deletions test/fail_compilation/diag7050a.d
@@ -0,0 +1,14 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag7050a.d(5): Error: safe function 'diag7050a.foo' cannot call system function 'diag7050a.Foo.this'
---
*/

#line 1
struct Foo {
this (int a) {}
}
@safe void foo() {
auto f = Foo(3);
}
15 changes: 15 additions & 0 deletions test/fail_compilation/diag7050b.d
@@ -0,0 +1,15 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag7050b.d(5): Error: pure function 'diag7050b.f.g' cannot call impure function 'diag7050b.f'
---
*/

#line 1
void f()
{
pure void g()
{
f();
}
}
22 changes: 22 additions & 0 deletions test/fail_compilation/diag7050c.d
@@ -0,0 +1,22 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag7050c.d(7): Error: safe function 'diag7050c.B.~this' cannot call system function 'diag7050c.A.~this'
---
*/

#line 1
struct A
{
~this(){}
}

@safe struct B
{
A a;
}

@safe void f()
{
auto x = B.init;
}