Difference between revisions of "Conversion rules"
(Added category) |
|||
Line 6: | Line 6: | ||
This article discusses issues recently discovered for the following two validity rules: | This article discusses issues recently discovered for the following two validity rules: | ||
− | 8.15.7 Validity: ''Conversion Procedure rule'', Validity code: '''VYCP'''<br> | + | * 8.15.7 Validity: ''Conversion Procedure rule'', Validity code: '''VYCP'''<br> |
− | 8.15.8 Validity: ''Conversion Query rule'', Validity code: '''VYCQ''' | + | * 8.15.8 Validity: ''Conversion Query rule'', Validity code: '''VYCQ''' |
+ | |||
+ | There are cases where both of them violate the conversion principle: | ||
+ | |||
+ | * 8.15.3 Validity: ''Conversion principle'': No type may both conform and convert to another. | ||
==Examples== | ==Examples== | ||
− | + | As the conversion rules are strongly dual, each example can be transformed to show the issue for its sibling. | |
====Example 1==== | ====Example 1==== | ||
− | eweasel test: convert-to-current-type | + | We have a conversion to the current type of the class. It should not be allowed. Currently no rule rejects this code. |
+ | |||
+ | * eweasel test: convert-to-current-type | ||
+ | |||
<code>[eiffel,N] | <code>[eiffel,N] | ||
class A[G] | class A[G] | ||
Line 19: | Line 26: | ||
feature | feature | ||
to_a: A[G] | to_a: A[G] | ||
+ | do end | ||
end | end | ||
</code> | </code> | ||
Line 29: | Line 37: | ||
Is A[ANY] conform to A[G]? | Is A[ANY] conform to A[G]? | ||
− | As we answer this question | + | As we answer this question with '''no''', the conversion is valid because all the other rules do not object either. |
====Example 2==== | ====Example 2==== | ||
− | eweasel test: convert-to- | + | This example shows a special case which is valid under the current rule but can possibly lead to a conflict between conformance and conversion. |
+ | |||
+ | * eweasel test: convert-to-possible-actual-type | ||
+ | |||
<code>[eiffel,N] | <code>[eiffel,N] | ||
class A[G] | class A[G] | ||
Line 39: | Line 50: | ||
feature | feature | ||
to_a: A[STRING] | to_a: A[STRING] | ||
+ | do end | ||
end | end | ||
</code> | </code> | ||
− | In the case where G's actual type parameter is a subtype of STRING the two types are conform again. | + | In the case where G's actual type parameter is a subtype of STRING it yields in a situation where the two types are conform again. |
The interesting rule is again '''VYCQ(3)''': | The interesting rule is again '''VYCQ(3)''': | ||
Line 48: | Line 60: | ||
This question is answered with '''no''' too. Therefore the conversion is valid. | This question is answered with '''no''' too. Therefore the conversion is valid. | ||
+ | |||
+ | ====Example 3==== | ||
+ | |||
+ | * eweasel test: convert-to-base-class | ||
+ | |||
+ | <code>[eiffel,N] | ||
+ | class A[G,H] | ||
+ | convert | ||
+ | to_a: {A[G,G]} | ||
+ | feature | ||
+ | to_a: A[G,G] | ||
+ | do end | ||
+ | end | ||
+ | </code> | ||
+ | |||
+ | '''VYCQ(3)''': | ||
+ | |||
+ | Is A[ANY,ANY] conform to A[G,G]? | ||
+ | |||
+ | The answer is '''no''' and thus not violating the rule, but it should. | ||
+ | |||
+ | ====Example 4==== | ||
+ | This is an example which is valid under the current rules and should remain valid. Even though we inherit from A[ANY] the conversion to A[STRING] should be valid. | ||
+ | |||
+ | * eweasel test: convert-to-base-class-inherited | ||
+ | |||
+ | <code>[eiffel,N] | ||
+ | class A[G] | ||
+ | end | ||
+ | |||
+ | class B[G] | ||
+ | inherit | ||
+ | A[ANY] | ||
+ | convert | ||
+ | to_b: {A[STRING]} | ||
+ | feature | ||
+ | to_b: A[STRING] | ||
+ | do end | ||
+ | end | ||
+ | </code> | ||
+ | |||
+ | '''VYCQ(3)''': | ||
+ | |||
+ | Is B[ANY] conform to A[STRING]? | ||
+ | |||
+ | This question is answered with '''no''' too. Therefore the conversion is valid, which is desired. | ||
+ | |||
+ | ==Possible solution== | ||
+ | Instead of restricting VYCQ(2) and VYCP(2) to non-generic types we allow them too. As VYC*(2) is even using the notion of ''current type'', it might indeed be possible that it was the authors original intention. | ||
+ | |||
+ | We define an additional function ''SUPER'' which replaces every formal generic with NONE. | ||
+ | (If used here one assumes that NONE conforms to expanded types as well.) | ||
+ | |||
+ | The new version could look like this: | ||
+ | * VYCP'(2) ''SUPER(SOURCE)'' does not conform to ''CT''. | ||
+ | * VYCQ'(2) ''SUPER(CT)'' does not conform to ''TARGET''. | ||
+ | |||
+ | |||
+ | ====New rule applied to examples==== | ||
+ | '''Example 1 for VYCQ'(2):''' | ||
+ | |||
+ | Is A[NONE] conform to A[G]? | ||
+ | |||
+ | The answer is '''yes''' and the validity rule is violated, which is good. | ||
+ | |||
+ | |||
+ | '''Example 2 for VYCQ'(2):''' | ||
+ | |||
+ | Is A[NONE] conform to A[STRING]? | ||
+ | |||
+ | The answer is '''yes''' and we reject the code. | ||
+ | |||
+ | |||
+ | '''Example 3 for VYCQ'(2):''' | ||
+ | |||
+ | Is A[NONE,NONE] conform to A[G,G]? | ||
+ | |||
+ | The answer is again '''yes''' and therefore the code not valid. | ||
+ | |||
+ | |||
+ | '''Example 4 for VYCQ'(2):''' | ||
+ | |||
+ | Is B[NONE] conform to A[STRING]? | ||
+ | |||
+ | As ''B'' only inherits from ''A[ANY]'' the answer is '''no''' and we're fine. |
Revision as of 09:46, 19 January 2007
Warning: Warning: Article under development
Contents
Introduction
This article discusses issues recently discovered for the following two validity rules:
- 8.15.7 Validity: Conversion Procedure rule, Validity code: VYCP
- 8.15.8 Validity: Conversion Query rule, Validity code: VYCQ
There are cases where both of them violate the conversion principle:
- 8.15.3 Validity: Conversion principle: No type may both conform and convert to another.
Examples
As the conversion rules are strongly dual, each example can be transformed to show the issue for its sibling.
Example 1
We have a conversion to the current type of the class. It should not be allowed. Currently no rule rejects this code.
- eweasel test: convert-to-current-type
class A[G] convert to_a: {A[G]} feature to_a: A[G] do end end
The conversion to A[G] should indeed not be valid because they are conform.
The only rule that matters in our case is VYCQ(3).
What VYCQ(3) asks is the following
Is A[ANY] conform to A[G]?
As we answer this question with no, the conversion is valid because all the other rules do not object either.
Example 2
This example shows a special case which is valid under the current rule but can possibly lead to a conflict between conformance and conversion.
- eweasel test: convert-to-possible-actual-type
class A[G] convert to_a: {A[STRING]} feature to_a: A[STRING] do end end
In the case where G's actual type parameter is a subtype of STRING it yields in a situation where the two types are conform again.
The interesting rule is again VYCQ(3):
Is A[ANY] conform to A[STRING]?
This question is answered with no too. Therefore the conversion is valid.
Example 3
- eweasel test: convert-to-base-class
class A[G,H] convert to_a: {A[G,G]} feature to_a: A[G,G] do end end
VYCQ(3):
Is A[ANY,ANY] conform to A[G,G]?
The answer is no and thus not violating the rule, but it should.
Example 4
This is an example which is valid under the current rules and should remain valid. Even though we inherit from A[ANY] the conversion to A[STRING] should be valid.
- eweasel test: convert-to-base-class-inherited
class A[G] end class B[G] inherit A[ANY] convert to_b: {A[STRING]} feature to_b: A[STRING] do end end
VYCQ(3):
Is B[ANY] conform to A[STRING]?
This question is answered with no too. Therefore the conversion is valid, which is desired.
Possible solution
Instead of restricting VYCQ(2) and VYCP(2) to non-generic types we allow them too. As VYC*(2) is even using the notion of current type, it might indeed be possible that it was the authors original intention.
We define an additional function SUPER which replaces every formal generic with NONE. (If used here one assumes that NONE conforms to expanded types as well.)
The new version could look like this:
- VYCP'(2) SUPER(SOURCE) does not conform to CT.
- VYCQ'(2) SUPER(CT) does not conform to TARGET.
New rule applied to examples
Example 1 for VYCQ'(2):
Is A[NONE] conform to A[G]?
The answer is yes and the validity rule is violated, which is good.
Example 2 for VYCQ'(2):
Is A[NONE] conform to A[STRING]?
The answer is yes and we reject the code.
Example 3 for VYCQ'(2):
Is A[NONE,NONE] conform to A[G,G]?
The answer is again yes and therefore the code not valid.
Example 4 for VYCQ'(2):
Is B[NONE] conform to A[STRING]?
As B only inherits from A[ANY] the answer is no and we're fine.