Number of yaql functions caused AmbiguousFunctionException

There are several commonly used MuranoPL-specific yaql functions
that were extension methods (i.e. those that can be called as both as functions
(foo($x)) and as methods ($x.foo())) before Murano switched to yaql 1.0
(because this was the only option for yaql 0.2). To keep backward compatibility
they remain such after migration to 1.0 but only for MuranoPL/1.0 format.
The new approach was to make them pure functions and auto convert to
extension methods for MuranoPL/1.0. However due to error both original
and auto-generated versions of the same functions were placed in the same
yaql context. As a result when attempts to call them as a functions
(say id($this)) caused AmbiguousFunctionException to be thrown because
both function versions would satisfy this syntax.

Change-Id: Ib58c64b999a309e51a7d4a86f5de4cdce84a86d6
Closes-Bug: #1501367
This commit is contained in:
Stan Lagun 2015-09-30 20:52:22 +03:00
parent c6520e75f3
commit c3aa795908
7 changed files with 47 additions and 5 deletions

View File

@ -184,6 +184,9 @@ def register(context, runtime_version):
context.register_function(not_equal)
if runtime_version < constants.RUNTIME_VERSION_2_0:
context2 = context.create_child_context()
for t in ('id', 'cast', 'super', 'psuper', 'type'):
for spec in utils.to_extension_method(t, context):
context.register_function(spec)
context2.register_function(spec)
return context2
return context

View File

@ -99,8 +99,7 @@ def create_context(runtime_version):
else:
context = ROOT_CONTEXT_20.create_child_context()
context[constants.CTX_YAQL_ENGINE] = choose_yaql_engine(runtime_version)
yaql_functions.register(context, runtime_version)
return context
return yaql_functions.register(context, runtime_version)
def choose_yaql_engine(runtime_version):

View File

@ -92,8 +92,19 @@ Methods:
Body:
- $.virtualMethod()
- trace('-')
- $.cast(CommonParent).virtualMethod()
- cast($, CommonParent).virtualMethod()
- trace('-')
- $.cast(ParentClass1).virtualMethod()
- trace('-')
- $.cast(ParentClass2).virtualMethod()
testSuper:
Body:
- super($, $.virtualMethod())
- $.super($.virtualMethod())
testPsuper:
Body:
- psuper($, $.virtualMethod())
- $.psuper($.virtualMethod())

View File

@ -10,7 +10,7 @@ Methods:
method1:
Body:
- trace('SingleInheritanceChild::method1')
- $.super($.method1())
- super($, $.method1())
method2:
Body:

View File

@ -270,3 +270,11 @@ Methods:
Contract: $.int()
Body:
- Return: $list.aggregate($1 + $2, $initializer)
testId:
Body:
Return: id($) + $.id()
testType:
Body:
Return: type($) + $.type()

View File

@ -236,3 +236,10 @@ class TestEngineYaqlFunctions(test_case.DslTestCase):
21,
self._runner.testAggregateWithInitializer([1, 2, 3, 4], 11)
)
def test_id(self):
obj_id = self._runner.root.object_id
self.assertEqual(obj_id * 2, self._runner.testId())
def test_type(self):
self.assertEqual('TestEngineFunctions' * 2, self._runner.testType())

View File

@ -53,3 +53,17 @@ class TestMultipleInheritance(test_case.DslTestCase):
'CommonParent::virtualMethod', '-',
'ParentClass2::virtualMethod'],
self.traces)
def test_super(self):
self._runner.on(self._multi_derived).testSuper()
self.assertItemsEqual(
['CommonParent::virtualMethod', 'ParentClass2::virtualMethod',
'CommonParent::virtualMethod', 'ParentClass2::virtualMethod'],
self.traces)
def test_psuper(self):
self._runner.on(self._multi_derived).testPsuper()
self.assertItemsEqual(
['CommonParent::virtualMethod', 'ParentClass2::virtualMethod',
'CommonParent::virtualMethod', 'ParentClass2::virtualMethod'],
self.traces)