EditorSyntax icon indicating copy to clipboard operation
EditorSyntax copied to clipboard

Properties called directly on @(Array) declaration not scoped.

Open DarkLite1 opened this issue 7 years ago • 7 comments

Methods look like a string when called between $():

image

Version: 1.28.0-insider (user setup)
Commit: ee6a21fa49bd1906bd1378c2f2714cd656409e5c
Date: 2018-09-11T05:18:39.589Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

DarkLite1 avatar Sep 12 '18 08:09 DarkLite1

From #1522

DarkLite1 avatar Sep 12 '18 08:09 DarkLite1

This is the same as issue #141.

Unfortunately I don't know how to combine them nor if I should.

PwshPally avatar Sep 12 '18 16:09 PwshPally

Thanks for that @PSPally. I'll close this as a dupe of #141.

TylerLeonhardt avatar Sep 12 '18 17:09 TylerLeonhardt

So, this is less that properties/methods within a sub-expression are incorrect and more that we didn't account for people calling methods on an array declaration.

subexpression

Now, your syntax is valid so I'll work on getting that added at some point; However, is there a reason for doing it that way in your code instead of just using $($ImportedMatrix.Count) or if $ImportedMatrix is not already an array coercing it before the hashtable? You'd be able to work around this for now if so:

PS C:\> $Array = 1..10
PS C:\> "$(@($Array).Count) Blah"
10 Blah

PS C:\> "$($Array.Count) Blah"
10 Blah

omniomi avatar Sep 13 '18 12:09 omniomi

Thanks for looking at this @omniomi . The reason is indeed that we're not certain that $ImportedMatrix has values in it so we cast it to an array to be sure we can use the count method.

DarkLite1 avatar Sep 13 '18 13:09 DarkLite1

A quick correction, (noting that static members are allowed here too). (I might be using a different scope for the member here than the regular syntax is using)

For the end of the array definition:

			"end": "(\\))((?:(?:\\.|::)(?:\\p{L}|\\d|_)+)*\\b)?",
			"endCaptures": {
				"1": {
					"name": "punctuation.section.group.end.powershell"
				},
				"2": {
					"name": "variable.other.member.powershell"
				}
			},

It also turns out that this can work for Hash table definitions as well:

@{name="bob";age=42}.count

msftrncs avatar Sep 14 '18 17:09 msftrncs

Add scriptblocks to the list of items that should have member access scoped, not a common item by any means, as I am not sure it has any practical uses in a script file.

msftrncs avatar Dec 20 '18 03:12 msftrncs