What is the purpose of the Restrictions parameter in the MetaObject constructor?

I am currently having a problem in my implementation of the DLR language, where subsequent calls to a method defined in the language occur with the same input parameters that were used when that method was first called.

So ... if I do this in my language:

PrintType( 34 );
PrintType( 34.1 );

      

... output:

Integer

Integer

Where would I expect:

Integer

Decimal

I suspect (but cannot confirm yet) that the problem arises from the following:

  • my call binding (subclass InvokeAction) generates the appropriate invocation expression and then returns a new MetaObject with that expression and Restrictions.Empty

  • so I think what might happen is that the Restrictions parameter tells the DLR when this construct can be reused for subsequent calls to this method, and since I am not putting any constraints on the property, the first construct (sorry, my terminology here is probably incorrect ... hope you get this idea)

So ... I think I need to use merging the constraints generated for each parameter ... by type, or perhaps by instance.

Can someone confirm or deny my thoughts? Any other possibilities I should look into for the behavior I see?

TIA ...

0


source to share


1 answer


Your thinking is correct. In this case, you need a type constraint - in general, you want to have as few constraints as possible so that the code can be used from as many sites as possible.



The way it works is that the DLR looks for a cached rule before asking your binder for a rule. Constraints are what will prevent the cached rule from being applied to a new set of inputs.

+1


source







All Articles