Community
Participate
Working Groups
There have been many discussions about the necessity of resolving implicit source in ResolveExp. Currently, in case a source of the ResolveExp is not set explicitly the compiler tries to find it among implicit variables. When implementing bug 252358 and bug 253051 I found that within (implicit) ObjectExps the target variable ('s' in the example below) must be put into the environment as an implicit variable. This is done to implement the idea (8.1.5): "object s:Schema { name := self.name; table := self.ownedElement->map class2table(); } Within an object expression, the properties of the target variable ('s' in our example) can be accessed directly. Thus the assignment expression "name := self.name" means "s.name := self.name"." However, in case resolve(resolveIn) expressions without source expression are used within object expressions they automatically get the implicit target variable as source. Consider the example below: mapping EPackage::myMapping() : EPackage { name := 'BBB' + resolveoneIn(EPackage::mySubmapping, EPackage).name; } Within the mapping implicit population section the compiler creates an implicit ObjectExp referring to the 'result' variable. The result variable is added to the environment as implicit in order to allow direct access to its properties and operations ('name' property in this example). As a consequence, resolveoneIn get the implicit source - the 'result' variable. Meanwhile, it is obvious that the script intends to use the ResolveInExp without source. Solution: disable ResolveExp/ResolveInExp implicit source resolution. The spec doesn't mention this feature explicitly, it was implemented in similarity with properties and operations. However, after allowing direct access to properties/operations of the target variable in the ObjectExp body this facility becomes detrimental.
I don't see any pitfalls with disabling implicit source lookup for resolve() family. User always can explicitly specify source in case. Also .qvto script human readability will benefit from making resolve() call semantic context-insensitive.
(In reply to comment #0) We can't disable optional source object for resolveIn, which is mentioned by the spec explicitly. For resolveIn, we do not have to use the same strategy for implicit source lookup as defined in lookup lookupImplicitSourceForOperation, etc. The spec says explicitly how to handle the case if the source is missing. Then we just have to check if we can safely handle the case with null source and document this as a breaking change.
(In reply to comment #2) BTW, resolve without a source is already guarded by a compilation error
Fixed.