When a model is translated, warnings may be present in the translation log. One of the frequently occurring warnings is the Redeclaration requires a subtype warning, this post looks at how to fix this issue.
Why does this warning occur?
The Redeclaration requires a subtype warning occurs when a component is redeclared to a class that does not contain everything that is in the base class.
A simple example
A base class called SISOBaseClass is created, as in Figure 1.
The SISOBaseClass base class has an input u, an output y and a parameter scale. A testing template is created to test components extended from the SISOBaseClass components, see Figure 2.
In Figure 2 sISOBlock is extended from SISOBaseClass.
A class is created that connects the input to the output, as in Figure 3.
Note that this PassThrough class does not have the scale parameter that is present in the SISOBaseClass base class.
A model to test PassThrough is created by extending the template in Figure 2. and redeclaring the sISOBlock component to be the PassThrough class. The Modelica code for this testing block is in Figure 4.
When the TestPathThrough model is checked by pressing F8 the following warning is generated:
Why is the warning generated in this example?
In the TestPathThrough example in Figure 5. the scale parameter is not present in the redeclaration PassThrough class; however, scale is present in the SISOBaseClass base class.
What modifications are required to remove this warning?
To correct the issue all the things that are in the base class must be in redeclaration class. The best way to ensure this warning does not occur is to extend the redeclaration class from the base class. In the example above, this means that the PassThrough class, in Figure 3., should be extended from SISOBaseClass.
Written by: Garron Fish – Chief Engineer
Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion