slint/sixtyfps_compiler/tests/syntax/lookup/for_lookup.60
Olivier Goffart c25538c982 Normalize identifiers to - instead of _
As a result
 - The error messages will now show the error with `-` instead of `_`
 - The LSP will auto-complete with -
 - The interpreter's list of properties will list the property with '-'
   (but we made the change so that set_property, get_property, and so on
   work also if passed a '-')
2021-08-10 22:21:01 +02:00

76 lines
2 KiB
Text

/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2021 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2021 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
Hello := Rectangle {
aaa := Text{ text: "aaa";
bbb := Text{ text: "bbb"; }
}
property<int> count: 5;
for foo[idx] in count: Rectangle {
x: idx * 1phx;
ccc := Text {
x: idx * 1phx;
text: aaa.text;
y: foo * 1phx;
}
}
for gre[mem] in err: Rectangle {
//^error{Unknown unqualified identifier 'err'}
x: mem * 1phx;
ddd := Text { text: ccc.text; }
// ^error{Cannot access id 'ccc'}
}
for plop in 0 : named_for := Rectangle {
Text { color: named_for.background; }
}
Text {
text: ccc.text;
// ^error{Cannot access id 'ccc'}
color: named_for.background;
// ^error{Cannot access id 'named_for'}
}
for aaa in aaa.text: Rectangle {
// ^error{Cannot convert string to model}
}
for plop in [1,2,3,4]: Rectangle {
x: plop * 1phx;
Rectangle {
background: plop;
// ^error{Cannot convert float to brush}
}
}
for pp[idx] in [1,3,2]: Rectangle {
x: idx * 1phx;
y: 25phx * pp;
}
for pp[idx] in [{a: 1phx, b: "P"},{a: 2phx, b: "Q"}]: Text {
x: pp.a;
text: pp.b;
y: pp.b;
// ^error{Cannot convert string to length}
property<int> ggg: pp;
// ^error{Cannot convert \{ a: physical-length,b: string,\} to int}
}
for pp[idx] in [{a: 1, b: "P"},{a: 2, c: 1}]: Text {
text: pp.b; // Ok! pp will have a, b and c properties, and b will be the empty string.
}
}