[flang] Non-fatal error for repeated access spec

When an access statement repeats the same attribute, make it a non-fatal
diagnostic. Also, include the previous specification in the message.

resolve11.f90 now illustrates both cases, fatal and non-fatal.

Original-commit: flang-compiler/f18@1f567c740a
Reviewed-on: https://github.com/flang-compiler/f18/pull/70
Tree-same-pre-rewrite: false
This commit is contained in:
Tim Keith 2018-04-25 10:46:39 -07:00
parent 94fa0fd890
commit cb37c3625a
2 changed files with 15 additions and 4 deletions

View file

@ -927,10 +927,18 @@ bool ResolveNamesVisitor::Pre(const parser::AccessStmt &x) {
// Set the access specification for this name.
void ResolveNamesVisitor::SetAccess(const parser::Name &name, Attr attr) {
Symbol &symbol{MakeSymbol(name)};
if (symbol.attrs().HasAny({Attr::PUBLIC, Attr::PRIVATE})) {
Say(name, "The accessibility of '%s' has already been specified"_err_en_US);
Attrs &attrs{symbol.attrs()};
if (attrs.HasAny({Attr::PUBLIC, Attr::PRIVATE})) {
// PUBLIC/PRIVATE already set: make it a fatal error if it changed
Attr prev = attrs.test(Attr::PUBLIC) ? Attr::PUBLIC : Attr::PRIVATE;
const auto &msg = attr == prev
? "The accessibility of '%s' has already been specified as %s"_en_US
: "The accessibility of '%s' has already been specified as %s"_err_en_US;
Say(Message{name.source,
parser::MessageFormattedText{
msg, name.ToString().c_str(), EnumToString(prev).c_str()}});
} else {
symbol.attrs().set(attr);
attrs.set(attr);
}
}

View file

@ -1,5 +1,8 @@
module m
public i
!ERROR: The accessibility of 'i' has already been specified
integer, private :: j
!ERROR: The accessibility of 'i' has already been specified as PUBLIC
private i
!The accessibility of 'j' has already been specified as PRIVATE
private j
end