Bug 402769 - Make conversion rules extensible by anvils / strict type conversion rules by default
Summary: Make conversion rules extensible by anvils / strict type conversion rules by ...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: VJET (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Justin Early CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-08 12:48 EST by Justin Early CLA
Modified: 2017-04-11 15:12 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Early CLA 2013-03-08 12:48:17 EST
There are multiple type conversions which may be ok for a specific type library / user defined types (not vjo.js) 

Such as:

Object[] -> T
ObjLiteral -> T
ObjLiteral[] -> T[]
ObjLiteral[] -> T

Sencha Specific examples:
Object -> Mixed == Object/Number/String/Boolean == any literal

Object[] -> MixedCollection = []
Object[] -> MixedCollection = []

We can specify these in the bootstrap.js or through a java api.

The type library bootstrap.js approach

// extend the conversion rules for anyone depending on this this library
var allowableConversionRules = {
    //  assign from : assign to
	// "AssignFrom" : ["AssignTO"] // allow assignment from AssignFrom type to AssignTO type
	// "AssignFrom" : "T" // allow assignment from AssignFrom type to any type
	"Object" : "T" // allow assignment from Object type to any type - case 1
    "Object[]" : "T[]" // allow assignment from Object[] type to any type - case 2
	"ObjLiteral" : "T" // allow assignment from ObjLiteral type to any type - case 3
	"ObjLiteral[]" : "T[]" // allow assignment from ObjLiteral[] type to any array type - case 4
	"
}


Unit test examples:

expect error without these conversion rules in bootstrap.js extension

case1 (Object -> String) 

//>void doIt(String)
function doIt(a){
	
}

//>void fn((void fn(Object)) fn)
function funWithCallBack(fn){
	
}

funWithCallBack(function(p0){
	doIt(p0); // should not get error here - "Invalid argument at 1: cannot convert from Object to String"
})


case2 (Object[] -> String[]) 

//>void doIt(String[])
function doIt(a){
	
}

//>void fn((void fn(Object[])) fn)
function funWithCallBack(fn){
	
}

funWithCallBack(function(p0){
	doIt(p0); // should not get error here - "Invalid argument at 1: cannot convert from Object[] to String[]"
})

case3 (ObjLiteral -> String)

//>void doIt(String)
function doIt(a){
	
}

//>void fn((void fn(ObjLiteral)) fn)
function funWithCallBack(fn){
	
}

funWithCallBack(function(p0){
	doIt(p0); // should not get error here - "Invalid argument at 1: cannot convert from ObjLiteral to String"
	var foo = {};
	doIt(foo);
})

case4 (ObjLiteral[] -> String[])

//>void doIt(String[])
function doIt(a){
	
}

//>void fn((void fn(ObjLiteral[])) fn)
function funWithCallBack(fn){
	
}

funWithCallBack(function(p0){
	doIt(p0); // should not get error here - "Invalid argument at 1: cannot convert from ObjLiteral[] to String[]"
	var foo = {};
	doIt(foo);
})


Setup Case 1

Create VJET Project
Load in test cases into project there should be problem markers because the default conversion rules are strict.

Setup Case 2

Create VJET Project
Add Bootstrap (from VJET menu)
Add conversionRules variable to bootstrap with desired rules (you can use the example above.
Load in test cases into project there should be no problem error markers

Other cases to consider:

1. MixedType
2. Variant Type
3. Parameterized Types
4. Multiple project scenario (higher priority)
5. Noticed issue with [] cases not giving validation errors currently to fix in 0.11
Comment 1 Justin Early CLA 2013-03-08 12:56:31 EST
Plan to implement this bug:

0.10 will have the Object -> T strict validation enabled by default.
0.10 Add a simple switch that extensions can disable the Object to T conversion rule and replace switch with better extension in 0.11
0.10 Adopter plugins can use the switch to disable Object-> T conversion errors. This will be a provisional api which is planned to be replaced in 0.11

In 0.11
1. I will by default make Case #1 and #2 conversion error (in 0.10) for revisit in 0.11. Case 3,4 are already not giving any errors in 0.10
2. Determine how many test failures there will be due to making this rule more strict. Document those test failures here.
3. Add unit test for the cases above. 
4. Add to test suite include Mixed and Variant type examples





2. In 0.11 we can make this configurable so users can turn on tighter validation as opt in case
3. Also in 0.11 we should look at vjet doc case for function callbacks 
4. In 0.11 we can also look at adding type converter extensions for exceptional cases such as the ones mentioned ObjectLiteral[] to MixedCollection so adopters/type library / anvil developers can have graduation level of forging their types.