X-Sharp / XSharpPublic

Public repository for the source code for the XSharp Compiler, Runtime, Project System and Tools.
Apache License 2.0
92 stars 36 forks source link

Some issues with indexed PROPERTY SET and ASSIGN #1543

Open cpyrgas opened 1 month ago

cpyrgas commented 1 month ago

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
*/
RobertvanderHulst commented 1 month ago

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

cpyrgas commented 1 month ago

Robert,

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

RobertvanderHulst commented 1 week ago

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

cpyrgas commented 1 week ago

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.

RobertvanderHulst commented 1 week ago

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 commented 1 week ago

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

cpyrgas commented 1 week ago

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