New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error compiling parameterized attribute #62

Open
weirdan opened this Issue Jan 7, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@weirdan
Contributor

weirdan commented Jan 7, 2016

When I tried to use NUnit I encountered the following error:

❯ ~/src/Phalanger/Deployment/Release/phpc.exe /pure+ /target:dll /lang:clr /out:obj/Debug/tests/XDebug.Protocol.test.dll test/Unit/Xdebug.Protocol.test.php $(pkg-config --libs nunit| sed s%-r:%/r:%g)
Phalanger - the PHP Language Compiler - version 4.0
for Microsoft (R) .NET Framework version 4.0
Encoding  cannot be loaded.
fileEncoding=""

Performing compilation ...
error PHP2007: Internal error! 
Please, report this bug via http://phalanger.codeplex.com/workitem/list/basic.
Additional information: 
Cannot convert to type System.Object[]
Parameter name: target_type
  at PHP.Core.ConvertToClr.ObjectToType (System.Object obj, System.Type target_type) <0x40cb6a00 + 0x00127> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+CustomAttributeCompiler.Emit (PHP.Core.CodeGenerator codeGen, IPhpCustomAttributeProvider target, Boolean force) <0x40cb51f0 + 0x003cf> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+CustomAttributeCompiler.Emit (PHP.Core.CodeGenerator codeGen, IPhpCustomAttributeProvider target) <0x40cb51c0 + 0x0001b> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.CustomAttributeCompilerHelper.Emit (PHP.Core.AST.CustomAttribute node, PHP.Core.CodeGenerator codeGen, IPhpCustomAttributeProvider target) <0x40cb5180 + 0x00030> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+CustomAttributesCompiler.Emit (PHP.Core.AST.CustomAttributes node, PHP.Core.CodeGenerator codeGenerator, IPhpCustomAttributeProvider target) <0x40cb50a0 + 0x0007b> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.CustomAttributesCompilerHelper.Emit (PHP.Core.AST.CustomAttributes node, PHP.Core.CodeGenerator codeGenerator, IPhpCustomAttributeProvider target) <0x40cb5050 + 0x00037> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+TypeMemberDeclCompiler`1[T].Emit (T node, PHP.Core.CodeGenerator codeGenerator) <0x40cb6900 + 0x00057> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+MethodDeclCompiler.Emit (PHP.Core.AST.MethodDecl node, PHP.Core.CodeGenerator codeGenerator) <0x40cb64d0 + 0x00027> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+TypeMemberDeclCompiler`1[T].PHP.Core.Compiler.AST.ITypeMemberDeclCompiler.Emit (PHP.Core.AST.TypeMemberDecl node, PHP.Core.CodeGenerator codeGenerator) <0x40cb6470 + 0x00055> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+TypeDeclCompiler.EmitDefinition (PHP.Core.CodeGenerator codeGenerator) <0x40cb4340 + 0x00159> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+TypeDeclCompiler.Emit (PHP.Core.AST.TypeDecl node, PHP.Core.CodeGenerator codeGenerator) <0x40cb40f0 + 0x00027> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+StatementCompiler`1[T].PHP.Core.Compiler.AST.IStatementCompiler.Emit (PHP.Core.AST.Statement node, PHP.Core.CodeGenerator codeGenerator) <0x40cb3f90 + 0x00052> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.StatementUtils.Emit (PHP.Core.AST.Statement statement, PHP.Core.CodeGenerator codeGenerator) <0x40cb3f50 + 0x00036> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+NamespaceDeclCompiler.Emit (PHP.Core.AST.NamespaceDecl node, PHP.Core.CodeGenerator codeGenerator) <0x40cb3ff0 + 0x0008b> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+StatementCompiler`1[T].PHP.Core.Compiler.AST.IStatementCompiler.Emit (PHP.Core.AST.Statement node, PHP.Core.CodeGenerator codeGenerator) <0x40cb3f90 + 0x00052> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.StatementUtils.Emit (PHP.Core.AST.Statement statement, PHP.Core.CodeGenerator codeGenerator) <0x40cb3f50 + 0x00036> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.NodeCompilers+GlobalCodeCompiler.Emit (PHP.Core.AST.GlobalCode ast, PHP.Core.CodeGenerator codeGenerator) <0x40cb2650 + 0x0023b> in <filename unknown>:0 
  at PHP.Core.Compiler.AST.GlobalCodeCompilerHelper.Emit (PHP.Core.AST.GlobalCode ast, PHP.Core.CodeGenerator codeGenerator) <0x40cb25f0 + 0x00036> in <filename unknown>:0 
  at PHP.Core.Reflection.CompilationSourceUnit.Emit (PHP.Core.CodeGenerator codeGenerator) <0x40cb1ad0 + 0x00123> in <filename unknown>:0 
  at PHP.Core.Reflection.PureCompilationUnit.Compile (IEnumerable`1 sourceFiles, PHP.Core.Emit.PureAssemblyBuilder assemblyBuilder, PHP.Core.CompilationContext context, System.Text.Encoding encoding) <0x40b997d0 + 0x0064b> in <filename unknown>:0 
  at PHP.Core.Emit.PureAssemblyBuilder.Build (IEnumerable`1 sourceFiles, PHP.Core.CompilationContext context) <0x40b92990 + 0x00073> in <filename unknown>:0 
  at PHP.Core.ApplicationCompiler.Compile (PHP.Core.ApplicationContext applicationContext, PHP.Core.CompilerConfiguration config, PHP.Core.ErrorSink errorSink, PHP.Core.CompilationParameters ps) <0x40b8e8e0 + 0x0083c> in <filename unknown>:0 


Build complete -- 1 error, 0 warnings.

Source code:

<?php
namespace Weirdan\Xdebug\Protocol\Tests;


use NUnit\Framework\TestFixtureAttribute as TestFixture,
    NUnit\Framework\TestAttribute as Test,
    NUnit\Framework\TestCaseAttribute as TestCase,
    NUnit\Framework\Assert,
    NUnit\Framework\Is;

[assembly:\Export]

[TestFixture]
class TestBasic
{
    [TestCase(12)]
    [\Export]
    function testSomething($arg)
    {
        Assert::That($arg, Is::EqualTo(12));
    }
}

If I take out [TestCase(12)] attribute (or replace it with [Test]) it compiles ok.

TestCaseAttribute is defined like this:

namespace NUnit.Framework
{
    [AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
    public class TestCaseAttribute : Attribute, ITestCaseData
    {
        //
        // Properties
        //
        public object[] Arguments { get; }

        public IList Categories { get; }

        public string Category { get; set; }

        public string Description { get; set; }

        public Type ExpectedException { get; set; }

        public string ExpectedExceptionName { get; set; }

        public string ExpectedMessage { get; set; }

        public object ExpectedResult { get; set; }

        public bool Explicit { get; set; }

        public bool HasExpectedResult { get; }

        public bool Ignore { get; set; }

        public bool Ignored { get; set; }

        public string IgnoreReason { get; set; }

        public MessageMatch MatchType { get; set; }

        public string Reason { get; set; }

        public object Result { get; set; }

        public string TestName { get; set; }

        //
        // Constructors
        //
        public TestCaseAttribute (params object[] arguments);

        public TestCaseAttribute (object arg);

        public TestCaseAttribute (object arg1, object arg2);

        public TestCaseAttribute (object arg1, object arg2, object arg3);
    }
}
@diddledan

This comment has been minimized.

Show comment
Hide comment
@diddledan

diddledan Feb 17, 2016

Contributor

I'm unsure how to fix this immediately other than the below potential, but very ugly, workaround. However, for a brief synopsis of what I think the problem is: It seems that the argument 12 is attempting to be converted into an array of System.Object but failing.

Possible workaround:
[TestCase(0=>12)]

Explanation of thinking: as it's expecting an array my suggestion is to attempt to convince the parser that 12 is the value of index 0 in an anonymous array.

Contributor

diddledan commented Feb 17, 2016

I'm unsure how to fix this immediately other than the below potential, but very ugly, workaround. However, for a brief synopsis of what I think the problem is: It seems that the argument 12 is attempting to be converted into an array of System.Object but failing.

Possible workaround:
[TestCase(0=>12)]

Explanation of thinking: as it's expecting an array my suggestion is to attempt to convince the parser that 12 is the value of index 0 in an anonymous array.

@bfistein

This comment has been minimized.

Show comment
Hide comment
@bfistein

bfistein Sep 19, 2018

Contributor

@weirdan Phalanger's development is mostly discontinued in favor of PeachPie, the more modern compiler and runtime that also targets .NET Core. Please feel free to give that a try.

Contributor

bfistein commented Sep 19, 2018

@weirdan Phalanger's development is mostly discontinued in favor of PeachPie, the more modern compiler and runtime that also targets .NET Core. Please feel free to give that a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment