[Qt-qml] patch for type resolving
Matthias Ettrich
matthias.ettrich at nokia.com
Thu Apr 15 16:40:07 CEST 2010
Fellow qml hackers,
I wasn't too happy with type shadowing and resolving in current qml.
Background: the implicit "." import has been moved to be the last import
checked. This was done in order to support our previous coding convention with
case insensitive file systems.
Example:
Foo/foo.qml imports "content" and instantiates Foo{}
content/Foo.qml implements Foo
with the correct lookup order, foo.qml would instantiate itself as Foo.qml -
which breaks.
This creates one big problem: If you add a type MyType.qml to your local
directory, you cannot be sure that it isn't shadowed by some import. If so,
the shadowing would be completely silent. This is unexpected behaviour and
hard to debug.
My suggestion (as implemented in the patch) is to disallow shadowing of types
completely. We don't need it since qml has excellent namespace and versioning
capabilities.
In addition I suggest to forbid recursive instantiations as well. A file
Button.qml should not instantiate the same Button.qml inside.
The above use case with the lowercase main file can be supported with a tiny
little trick: if a file would instantiate itself recursively, but the "same"
type can be found elsewhere, take it from elsewhere and continue.
Works like a charm :)
The patch breaks a few testcases in qdeclarativelanguage due to its more
explicit error messages and the strict no-shadowing policy. Warwick, Aaron et.
al., if you like the idea, I will fix the tests.
Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: resolveType.pach
Type: text/x-patch
Size: 15092 bytes
Desc: not available
Url : http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100415/a0ef2262/attachment.bin
More information about the Qt-qml
mailing list