diff options
Diffstat (limited to 'src/vhdl/sem_scopes.adb')
-rw-r--r-- | src/vhdl/sem_scopes.adb | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/vhdl/sem_scopes.adb b/src/vhdl/sem_scopes.adb index 17e3847ed..417eecf5c 100644 --- a/src/vhdl/sem_scopes.adb +++ b/src/vhdl/sem_scopes.adb @@ -404,6 +404,28 @@ package body Sem_Scopes is return Inter >= Current_Region_Start; end Is_In_Current_Declarative_Region; + -- Emit a warning when DECL hides PREV_DECL. + procedure Warning_Hide (Decl : Iir; Prev_Decl : Iir) + is + begin + if Get_Kind (Decl) in Iir_Kinds_Interface_Declaration + and then Get_Kind (Get_Parent (Decl)) = Iir_Kind_Component_Declaration + then + -- Do not warn when an interface in a component hides a declaration. + -- This is a common case (eg: in testbenches), and there is no real + -- hiding. + return; + end if; + + if Decl = Prev_Decl then + -- Can happen in configuration. No real hidding. + return; + end if; + + Warning_Msg_Sem (Warnid_Hide, +Decl, + "declaration of %i hides %n", (+Decl, +Prev_Decl)); + end Warning_Hide; + -- Add interpretation DECL to the identifier of DECL. -- POTENTIALLY is true if the identifier comes from a use clause. procedure Add_Name (Decl : Iir; Ident : Name_Id; Potentially : Boolean) @@ -919,8 +941,11 @@ package body Sem_Scopes is -- declarative region if the inner region contains an homograph -- of this declaration; the outer declaration is the hidden -- within the immediate scope of the inner homograph. - Warning_Msg_Sem (Warnid_Hide, +Decl, - "declaration of %i hides %n", (+Decl, +Current_Decl)); + if Is_Warning_Enabled (Warnid_Hide) + and then not Is_Potentially_Visible (Current_Inter) + then + Warning_Hide (Decl, Current_Decl); + end if; Add_New_Interpretation (True); end Add_Name; |