Git Product home page Git Product logo

Comments (2)

nickg avatar nickg commented on August 26, 2024

Subtypes are not distinct for the purposes of overload resolution. See section 4.5.1 of the 2008 LRM:

Two formal parameter lists are said to have the same parameter type profile if and only if they have the same number of parameters, and if at each parameter position the corresponding parameters have the same base type.

The error above then follows from the visibility rules in section 12.3:

Each of two declarations is said to be a homograph of the other if and only if both declarations have the same designator, and they denote different named entities, and either overloading is allowed for at most one of the two, or overloading is allowed for both declarations and they have the same parameter and result type profile (see 4.5.1).

So the two functions above are homographs since they have the same designator (has_rd), the parameter base types are the same (bit_vector), and the return type is the same. Then:

Two declarations that occur immediately within the same declarative region, [..], shall not be homographs, unless exactly one of them is the implicit declaration of a predefined operation or is an implicit alias of such an implicit declaration.

The error message could probably be improved a bit though.

For your example to work you need to make instruction32_t and opcode32_t separate types rather than subtypes. Something like:

  type instruction32_t is array (31 downto 0) of bit;
  type opcode32_t is array (6 downto 0) of bit;

  function has_rd(op  : opcode32_t) return boolean;
  function has_rd(ins : instruction32_t) return boolean;

FWIW ModelSim gives a very similar error:

** Error: test.vhd(6): (vcom-1295) Function "has_rd" has already been defined in this region.
** =====> Prior declaration of "has_rd" is at test.vhd(5).
** Note: test.vhd(7): VHDL Compiler exiting

from nvc.

nickg avatar nickg commented on August 26, 2024

It now reports this:

** Error: homograph of HAS_RD [INSTRUCTION32_T return BOOLEAN] already declared in this region
   > test.vhd:6
   |
 5 |   function has_rd(op  : opcode32_t) return boolean;
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ previous declaration was here
 6 |   function has_rd(ins : instruction32_t) return boolean;
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate declaration
   |
   = Note: only the base type is considered when determining if two overloads have the same 
           parameter type profile

from nvc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.