[Mono-dev] Compiler bug with Generics and where constraints

Alan McGovern alan.mcgovern at gmail.com
Mon Jul 16 16:46:09 EDT 2007


I suggested the same thing, but was told the compiler didn't allow you to
add constraints to the overridden method. Also, i believe his code compiles
fine under csc, so unless it's a bug in CSC, there's definitely an issue
here.

Alan.

On 7/16/07, Adar Wesley <adar.wesley at gmail.com> wrote:
>
> Hi John,
>
> It seams to me there is a problem with the code.  (I don't know if it
> worked before)
> In
>
>    1. protected static T
>    GetBusinessQueryObjectFromReader<T>(IDataReader reader)
>    2. 74             where T : BusinessQueryObject, new()
>
> The generic parameter T is contained.  However in:
> public override T[] GetQueryObjects<T>(string query, params
> QueryParameter[] parameters)
> T is not constrained.
>
> When you try to call GetBusinessQueryObjectFromReader<T>(IDataReader
> reader)
> from within GetQueryObjects<T> with the same generic parameter you get the
> error.
>
> Either add the same constraint on T in the decleration of
> GetQueryObjects<T> or remove
> the constraint from GetBusinessQueryObjectFromReader<T>.
>
> ---
> Adar Wesley
>
>
> On 7/16/07, John Anderson <sontek at gmail.com> wrote:
>
> > I tried making a smaller example but couldn't reproduce the error
> > because i'm not exactly sure whats causing it.
> >
> > Heres the code:
> > http://dev.orchidesolutions.com/testcode.tar.bz2
> >
> > if you run 'nant'  you'll see the error, its:
> >
> >
> >    1. [nant] /home/sontek/code/personal/devtoo/trunk/src/DataArch.
> >    DataFactory.MsSqlDatabase/DataArch.DataFactory.MsSqlDatabase.dll .
> >    build build
> >    2.             Buildfile: file:
> >    ///home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.MsSqlDatabase/DataArch.DataFactory.MsSqlDatabase.dll.build
> >    3.             Target framework: Mono 2.0 Profile
> >    4.             Target(s ) specified: build
> >    5.
> >    6.
> >    7.             build:
> >    8.
> >    9.                  [echo] Build Directory is
> >    <http://www.google.com/search?q=is+msdn.microsoft.com>
> >    /home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.
> >    MsSqlDatabase/bin/Release
> >    10.                   [csc] Compiling 3 files to '/home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.MsSqlDatabase/bin/Release/DataArch.DataFactory.MsSqlDatabase.dll'
> >    .
> >    11.                   [csc]/home/sontek/code/personal/devtoo/trunk/src/DataArch.
> >    DataFactory. MsSqlDatabase/MsSqlDataObjectFactory.cs(351 ,30):
> >    warning CS0219: The variable `columnsToUpdate ' is assigned but
> >    its value is never used
> >    12.                   [csc]
> >    /home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.MsSqlDatabase/MsSqlDataObjectFactory.cs(479,30):
> >    error CS0309: The type `T' must be convertible to `DataArch.
> >    DataFactory.Common.BusinessQueryObject' in order to use it as
> >    parameter `T' in the generic type or method `DataArch.DataFactory.Common
> >    .BaseDataObjectFactory.GetBusinessQueryObjectFromReader <T>(System
> >    .Data.IDataReader)'
> >    13.                   [csc]
> >    /home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.Common/bin/Release/DataArch.DataFactory.Common.dll
> >    (Location of the symbol related to previous error)
> >    14.                   [csc]
> >    /home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.MsSqlDatabase/MsSqlDataObjectFactory.cs(462,9):
> >    (Location of the symbol related to previous error)
> >    15.                   [csc]
> >    /home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.MsSqlDatabase/MsSqlDataObjectFactory.cs(479,30):
> >    error CS0309: The type `T' must be convertible to `DataArch.
> >    DataFactory.Common.BusinessQueryObject' in order to use it as
> >    parameter `T' in the generic type or method `DataArch.DataFactory.Common
> >    .BaseDataObjectFactory.GetBusinessQueryObjectFromReader <T>(System
> >    .Data.IDataReader)'
> >    16.                   [csc]
> >    /home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.Common/bin/Release/DataArch.DataFactory.Common.dll
> >    (Location of the symbol related to previous error)
> >    17.                   [csc]
> >    /home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.MsSqlDatabase/MsSqlDataObjectFactory.cs(462,9):
> >    (Location of the symbol related to previous error)
> >    18.                   [csc] Compilation failed: 2 error(s), 1
> >    warnings
> >    19.
> >    20.             BUILD FAILED - 0 non-fatal error(s), 7 warning(s)
> >    21.
> >    22.
> >    /home/sontek/code/personal/devtoo/trunk/src/DataArch.DataFactory.MsSqlDatabase/DataArch.DataFactory.MsSqlDatabase.dll.build(12,10):
> >    23.             External Program Failed:
> >    /usr/lib/pkgconfig/../../lib/mono/2.0/gmcs.exe (return code was 1)
> >    24.
> >    25.             Total time: 1 seconds.
> >    26.
> >    27.
> >    28. ======= MsSqlDataObjectFactory =================
> >    29.
> >    30.   public override T[] GetQueryObjects<T>(string query, params
> >    QueryParameter[] parameters)
> >    31. 462         {
> >    32. 463             DbCommand command = this.CreateNewCommand();
> >    33. 464
> >    34. 465              command.CommandText = query;
> >    35. 466             foreach (QueryParameter parameter in
> >    parameters)
> >    36. 467             {
> >    37. 468                 DbParameter dbParameter =
> >    command.CreateParameter();
> >    38. 469                 dbParameter.ParameterName = parameter.Name
> >    ;
> >    39. 470                 dbParameter.Value = parameter.Value;
> >    40. 471                 command.Parameters.Add(dbParameter);
> >    41. 472             }
> >    42. 473
> >    43. 474             List<T> list = new List<T>();
> >    44. 475
> >    45. 476             ExecuteReader(command,
> >    46. 477                 delegate(IDataReader reader)
> >    47. 478                 {
> >    48. 479                     list.Add(GetBusinessQueryObjectFromReader<T>(reader));
> >
> >    49. 480                 });
> >    50. 481
> >    51. 482             return list.ToArray();
> >    52. 483         }
> >    53.
> >    54.
> >    55.
> >    56. ====== BASE  ==========
> >    57.
> >    58.   protected static T
> >    GetBusinessQueryObjectFromReader<T>(IDataReader reader)
> >    59. 74             where T : BusinessQueryObject, new()
> >    60. 75         {
> >    61. 76             QueryDataObject data = new
> >    QueryDataObject(reader);
> >    62. 77             T t = new T();
> >    63. 78             t.data = data;
> >    64. 79             return t;
> >    65. 80         }
> >    66.
> >    67.
> >    68. public abstract T[] GetQueryObjects<T>(string query, params
> >    QueryParameter[] parameters)
> >    69. 91             where T : BusinessQueryObject, new();
> >
> >
> >
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-devel-list
> >
> >
>
>
> --
> ---
> Adar Wesley
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070716/0ad47024/attachment.html 


More information about the Mono-devel-list mailing list