XSharpPublic icon indicating copy to clipboard operation
XSharpPublic copied to clipboard

Some issues with indexed PROPERTY SET and ASSIGN

Open cpyrgas opened this issue 1 year ago • 2 comments

See inline for some issues with property/assign. I also think there is a mismatch with the order of arguments/parameters when defining/calling the assign in the wrong order, but the error XS1501 (no correct overload) hides this at the moment

FUNCTION Start( ) AS VOID
	TestClass{}:TestProp[TRUE,"b",1] := 123
	TestClass{}:TestAssign[TRUE,"b",1] := 123 // No overload for method 'TestClass.TestAssign[string, int]' takes 3 arguments
RETURN

CLASS TestClass
	PROPERTY TestPropCrash[c1 AS LOGIC , c2 AS STRING, nValue AS INT] AS INT SET // compiler crash (if other errors are resolved)
	PROPERTY TestPropEmpty[c1 AS LOGIC , c2 AS STRING, nValue AS INT] AS INT SET NOP // error XS0103: The name 'NOP' does not exist in the current context
	
	PROPERTY TestProp[c1 AS LOGIC , c2 AS STRING, nValue AS INT] AS INT 
	SET 
		? c1,c2,nValue
	END SET
	END PROPERTY
	
	ASSIGN TestAssign(c1 AS LOGIC , c2 AS STRING, nValue AS INT) AS INT
		? c1,c2,nValue
	RETURN
END CLASS

/*
Unhandled Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at LanguageService.Cci.FullMetadataWriter.GetFieldDefinitionHandle(IFieldDefinition def) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\FullMetadataWriter.cs:line 164
   at LanguageService.Cci.MetadataWriter.GetFieldHandle(IFieldReference fieldReference) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 843
   at LanguageService.Cci.MetadataWriter.GetHandle(Object reference) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 3078
   at LanguageService.Cci.MetadataWriter.ResolveEntityHandleFromPseudoToken(Int32 pseudoSymbolToken) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 3104
   at LanguageService.Cci.MetadataWriter.WriteInstructions(Blob finalIL, ImmutableArray`1 generatedIL, UserStringHandle& mvidStringHandle, Blob& mvidStringFixup) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 3220
   at LanguageService.Cci.MetadataWriter.SerializeMethodBody(MethodBodyStreamEncoder encoder, IMethodBody methodBody, StandaloneSignatureHandle localSignatureHandleOpt, UserStringHandle& mvidStringHandle, Blob& mvidStringFixup) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 2990
   at LanguageService.Cci.MetadataWriter.SerializeMethodBodies(BlobBuilder ilBuilder, PdbWriter nativePdbWriterOpt, Blob& mvidStringFixup) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 2925
   at LanguageService.Cci.MetadataWriter.BuildMetadataAndIL(PdbWriter nativePdbWriterOpt, BlobBuilder ilBuilder, BlobBuilder mappedFieldDataBuilder, BlobBuilder managedResourceDataBuilder, Blob& mvidFixup, Blob& mvidStringFixup) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\MetadataWriter.cs:line 1822
   at LanguageService.Cci.PeWriter.WritePeToStream(EmitContext context, CommonMessageProvider messageProvider, Func`1 getPeStream, Func`1 getPortablePdbStreamOpt, PdbWriter nativePdbWriterOpt, String pdbPathOpt, Boolean metadataOnly, Boolean isDeterministic, Boolean emitTestCoverageData, Nullable`1 privateKeyOpt, CancellationToken cancellationToken) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\PEWriter\PeWriter.cs:line 81
   at LanguageService.CodeAnalysis.Compilation.SerializePeToStream(CommonPEModuleBuilder moduleBeingBuilt, DiagnosticBag metadataDiagnostics, CommonMessageProvider messageProvider, Func`1 getPeStream, Func`1 getMetadataPeStreamOpt, Func`1 getPortablePdbStreamOpt, PdbWriter nativePdbWriterOpt, String pdbPathOpt, Boolean metadataOnly, Boolean includePrivateMembers, Boolean isDeterministic, Boolean emitTestCoverageData, Nullable`1 privateKeyOpt, CancellationToken cancellationToken) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\Compilation\Compilation.cs:line 2970
   at LanguageService.CodeAnalysis.Compilation.SerializeToPeStream(CommonPEModuleBuilder moduleBeingBuilt, EmitStreamProvider peStreamProvider, EmitStreamProvider metadataPEStreamProvider, EmitStreamProvider pdbStreamProvider, Func`2 testSymWriterFactory, DiagnosticBag diagnostics, EmitOptions emitOptions, Nullable`1 privateKeyOpt, CancellationToken cancellationToken) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\Compilation\Compilation.cs:line 2869
   at LanguageService.CodeAnalysis.CommonCompiler.CompileAndEmit(TouchedFileLogger touchedFilesLogger, Compilation& compilation, ImmutableArray`1 analyzers, ImmutableArray`1 generators, ImmutableArray`1 additionalTextFiles, AnalyzerConfigSet analyzerConfigSet, ImmutableArray`1 sourceFileAnalyzerConfigOptions, ImmutableArray`1 embeddedTexts, DiagnosticBag diagnostics, CancellationToken cancellationToken, CancellationTokenSource& analyzerCts, Boolean& reportAnalyzer, AnalyzerDriver& analyzerDriver) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 1283
   at LanguageService.CodeAnalysis.CommonCompiler.RunCore(TextWriter consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 839
   at LanguageService.CodeAnalysis.CommonCompiler.Run(TextWriter consoleOutput, CancellationToken cancellationToken) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\Portable\CommandLine\CommonCompiler.cs:line 706
   at LanguageService.CodeAnalysis.XSharp.CommandLine.Xsc.<>c__DisplayClass1_0.<Run>b__0(TextWriter tw) in D:\a\XSharpPublic\XSharpPublic\src\Compiler\src\Compiler\xsc\Xsc.cs:line 54
   at LanguageService.CodeAnalysis.CommandLine.ConsoleUtil.RunWithUtf8Output[T](Func`2 func) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Core\CommandLine\ConsoleUtil.cs:line 26
   at LanguageService.CodeAnalysis.XSharp.CommandLine.Xsc.Run(String[] args, BuildPaths buildPaths, TextWriter textWriter, IAnalyzerAssemblyLoader analyzerLoader) in D:\a\XSharpPublic\XSharpPublic\src\Compiler\src\Compiler\xsc\Xsc.cs:line 56
   at LanguageService.CodeAnalysis.CommandLine.BuildClient.RunLocalCompilation(String[] arguments, BuildPaths buildPaths, TextWriter textWriter) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Shared\BuildClient.cs:line 213
   at LanguageService.CodeAnalysis.CommandLine.BuildClient.RunCompilation(IEnumerable`1 originalArguments, BuildPaths buildPaths, TextWriter textWriter, String pipeName) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Shared\BuildClient.cs:line 154
   at LanguageService.CodeAnalysis.CommandLine.BuildClient.Run(IEnumerable`1 arguments, RequestLanguage language, CompileFunc compileFunc, ICompilerServerLogger logger) in D:\a\XSharpPublic\XSharpPublic\src\Roslyn\Src\Compilers\Shared\BuildClient.cs:line 98
   at LanguageService.CodeAnalysis.XSharp.CommandLine.Program.MainCore(String[] args) in D:\a\XSharpPublic\XSharpPublic\src\Compiler\src\Compiler\xsc\Program.cs:line 37
   at LanguageService.CodeAnalysis.XSharp.CommandLine.Program.Main(String[] args) in D:\a\XSharpPublic\XSharpPublic\src\Compiler\src\Compiler\xsc\Program.cs:line 19
*/

cpyrgas avatar Aug 13 '24 09:08 cpyrgas

Chris, The first parameter of the assign is the value that gets assigned. The other parameters are the indices.

So ASSIGN TestAssign(c1 AS LOGIC , c2 AS STRING, nValue AS INT) AS INT declares an assign that expects a logical value and has 2 indices of type STRING and INT The 'AS INT' at the end is ignored. Assigns do not have a return value. To achieve what you, want the assign must be declared as:

ASSIGN TestAssign(iValue as INT, c1 AS LOGIC , c2 AS STRING, nValue AS INT) AS VOID

RobertvanderHulst avatar Aug 13 '24 10:08 RobertvanderHulst

Robert,

Ah, sorry about that. I'm brain damaged, it's just too hot for too long..

cpyrgas avatar Aug 13 '24 11:08 cpyrgas

I have added an error: error XS9128: Indexed properties cannot be declared with single line GET/SET Accessors.

RobertvanderHulst avatar Sep 03 '24 13:09 RobertvanderHulst

There were some tests in the suite that were using single line indexed properties and failed, but I changed them to multiline and are ok now. I don't think this will affect many users (famous last words...), and it's easy to adjust the code anyway (with a descriptive error message), so confirmed fixed.

cpyrgas avatar Sep 08 '24 14:09 cpyrgas

Nikos has code in the runtime that uses the single line syntax for index properties. This is valid code and should work. I'll reopen this to allow that variant.

RobertvanderHulst avatar Sep 08 '24 15:09 RobertvanderHulst

The difference is that his code does not have empty GET and SET accessors, but there is indeed an expression inside the GET and SET accessors

RobertvanderHulst avatar Sep 08 '24 15:09 RobertvanderHulst

Ahhh, OK, I will also revert back the tests then.

cpyrgas avatar Sep 08 '24 16:09 cpyrgas

Still doesn't look good to me. For this code:

PROPERTY TestProp1[c1 AS LOGIC , nValue AS INT] AS INT SET

the compiler reports error XS9127: Indexed properties cannot be an AUTO property, but this is not an AUTO property, it is only a regular property with an inline SET

When I try to add a NOP instruction:

PROPERTY TestProp3[c1 AS LOGIC , nValue AS INT] AS INT SET NOP

I still get a compiler error XS0103: The name 'NOP' does not exist in the current context, which is also bogus

cpyrgas avatar Sep 20 '24 13:09 cpyrgas

Chris,

PROPERTY TestProp1[c1 AS LOGIC , nValue AS INT] AS INT SET

There is no code in SET, so that is why it matches the 'Auto' rule

And NOP is our keyword for an empty statement, not an expression. The single line SET expects an expression.

RobertvanderHulst avatar Sep 20 '24 13:09 RobertvanderHulst

Robert, doesn't the AUTO rule depend on the use of the AUTO keyword? I think it should.

cpyrgas avatar Sep 20 '24 14:09 cpyrgas

Oh, I see, it is possible to do this and it becomes an AUTO property without specifying AUTO:

PROPERTY ppp AS INT PRIVATE GET SET

I don't like this, but I understand now.

Confirmed fixed.

cpyrgas avatar Sep 20 '24 14:09 cpyrgas