#import #library questions. Why doesn't this work... / what's this for?

34 views
Skip to first unread message

chrisbuckett

unread,
Oct 16, 2011, 5:34:32 AM10/16/11
to General Dart Discussion
I've been playing with #import, and I've found a couple of confusing
things.

Given the file myLibrary.dart
01: #library("wibble");
02: class MyClass() {}

And the file myApp.dart
01: #library("myApp");
02: #import("myLibrary.dart", prefix:"myLib");
03
04: void main() {
05: myLib.MyClass my_class = new myLib.MyClass();
06: }



1. This generates a compilation error pointing at line 05: my_class -
"Unexpected token 'IDENTIFIER' (expected ';')"
Changing lines in app.dart (to remove the prefix) fixes the
compilation error:
02: #import("myLibrary.dart");
05: MyClass my_class = new MyClass();
Question: Should the original code listed above work?


2. the #library statement in myLibrary.dart:01 appears to bear no
reference to the filename / folder location.
- I have found, though, that the #library name is what appears in the
dartEditor, (but you can only view the files that make up that library
if they live in a different folder to the myApp.dart library - I'm
guessing that this a problem with DartEditor, as it doesn't seem to
affect compilation)
Question: Are there any recommendations around the #library names and
how they should relate to filename / folder paths?

Thanks

Chris Buckett.

-----------------------------
http://dartwatch.com

Florian Loitsch

unread,
Oct 16, 2011, 8:24:02 AM10/16/11
to chrisbuckett, General Dart Discussion
On Sun, Oct 16, 2011 at 11:34, chrisbuckett <chrisb...@gmail.com> wrote:
I've been playing with #import, and I've found a couple of confusing
things.

Given the file myLibrary.dart
01: #library("wibble");
02: class MyClass() {}

And the file myApp.dart
01: #library("myApp");
02: #import("myLibrary.dart", prefix:"myLib");
03
04: void main() {
05:   myLib.MyClass my_class = new myLib.MyClass();
06: }



1.  This generates a compilation error pointing at line 05: my_class -
"Unexpected token 'IDENTIFIER' (expected ';')"
Changing lines in app.dart  (to remove the prefix) fixes the
compilation error:
02: #import("myLibrary.dart");
05:   MyClass my_class = new MyClass();
Question: Should the original code listed above work?
Afaics it should work. I will investigate on Monday. 


2. the #library statement in myLibrary.dart:01  appears to bear no
reference to the filename / folder location.
- I have found, though, that the #library name is what appears in the
dartEditor, (but you can only view the files that make up that library
if they live in a different folder to the myApp.dart library - I'm
guessing that this a problem with DartEditor, as it doesn't seem to
affect compilation)
This seems to be an editor bug.
 
Question: Are there any recommendations around the #library names and
how they should relate to filename / folder paths? 
The #-library directives were added very recently and I would not be surprised if they changed. (In particular there seems to be no reason to require a #library).
I wasn't directly involved with the latest revision of the library-syntax, but I will try to get more information from those that were on Monday.

// florian

Thanks

Chris Buckett.

-----------------------------
http://dartwatch.com



--
Give a man a fire and he's warm for the whole day,
but set fire to him and he's warm for the rest of his life. - Terry Pratchett

Keerti Parthasarathy

unread,
Oct 17, 2011, 5:35:17 PM10/17/11
to Florian Loitsch, chrisbuckett, General Dart Discussion

Yes, it is a problem with the Dart Editor. We hope to have it fixed soon.

>
>>
>> Question: Are there any recommendations around the #library names and
>> how they should relate to filename / folder paths?
>
> The #-library directives were added very recently and I would not be
> surprised if they changed. (In particular there seems to be no reason to
> require a #library).
> I wasn't directly involved with the latest revision of the library-syntax,
> but I will try to get more information from those that were on Monday.
> // florian
>>
>> Thanks
>>
>> Chris Buckett.
>>
>> -----------------------------
>> http://dartwatch.com
>
>
>
> --
> Give a man a fire and he's warm for the whole day,
> but set fire to him and he's warm for the rest of his life. - Terry
> Pratchett
>

--
Keerti

Florian Loitsch

unread,
Oct 18, 2011, 6:26:16 AM10/18/11
to chrisbuckett, Keerti Parthasarathy, General Dart Discussion
And there seems to be a bug in DartC too. Filed issue 160. (sorry for the typo in your name).
// florian
Reply all
Reply to author
Forward
0 new messages