Nemerle vs C#: array[object] and arrya[string] are not compa
От: Ilya10k Россия  
Дата: 20.09.06 02:08
Оценка:
А это баг?

Код на C# работает отлично:
using System;
using System.Windows.Forms;

namespace Test
{
    class Form1: Form
    {
        static void Main()
        {
            Application.Run(new Form1());
        }

        private Form1()
        {
            string[] strings = new string[]{"test1", "test2", "test3"};
            ComboBox comboBox1 = new ComboBox();
            comboBox1.Items.AddRange(strings);
            this.Controls.Add(comboBox1);
        }
    }
}


D:>csc test.cs
Версия компилятора Microsoft (R) Visual C# 20058.00.50727.42
для Microsoft (R) Windows (R) 2005 Framework версии2.0.50727
Авторские права (C) Microsoft Corporation 2001-2005. Все права защищены.


D:>



Код на Nemerle не компилируется:
using System;
using System.Windows.Forms;

namespace Test
{
    class Form1: Form
    {
        static Main() :  void
        {
            Application.Run( Form1());
        }

        private this()
        {
            def strings = array["test1", "test2", "test3"];
            def comboBox1 = ComboBox();
            comboBox1.Items.AddRange(strings);
            this.Controls.Add(comboBox1);
        }
    }
}


D:>ncc -r System.Windows.Forms test.n
test.n:17:1:17:25: <[01;31merror<[0m: in argument #1 (items) of comboBox1.Items.AddRange, needed a array [System.Object], got array [string]: the types System.Object and string are not compatible [simple unify]

D:>



Workaround:
using System;
using System.Windows.Forms;

namespace Test
{
    class Form1: Form
    {
        static Main() :  void
        {
            Application.Run( Form1());
        }

        private this()
        {
            def strings = array["test1", "test2", "test3"];
            def arr = Array.ConvertAll(strings, Converter.[string, object](fun(from){from}));
            def comboBox1 = ComboBox();
            comboBox1.Items.AddRange(arr);
            this.Controls.Add(comboBox1);
        }
    }
}


D:>ncc -r System.Windows.Forms test1.n


D:>test1.exe


D:>


30.01.07 18:14: Перенесено модератором из 'Декларативное программирование' — IT
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.