AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 15.11.2011, 01:13   #1  
Blog bot is offline
Blog bot
Участник
 
25,626 / 848 (80) +++++++
Регистрация: 28.10.2006
X++: X++ Compiler Changes in Dynamics AX 2012
Источник: http://blogs.msdn.com/b/x/archive/20...s-ax-2012.aspx
==============

In Microsoft Dynamics AX 2012, we made compiler changes to make the X++ language more reliable and to prevent problems that may cause runtime errors.

1. Super() cannot Call an Abstract Method

Suppose an abstract method is implemented by a derived class. If the method in the derived class tries to call super() to reach the abstract method in the base class, the X++ compiler will report an error. For example:

// X++ class BaseClass
{
public abstract int method1()
{ }
}

class DerivedClass extends BaseClass
{
public int method1()
{
return super(); // Invalid call.
}
}





Reason for the Change

Abstract methods have no code body. Therefore any call to an abstract method is meaningless.



2. All Default Parameters are required to follow the Last Non-default

The X++ compiler rejects any method parameter signature which lists a default parameter before the last regular non-default parameter.

In the following X++ method signatures, parameter ‘i’ is a default parameter that causes both methods to fail to compile.



public void myInvalidMethod1(int i=1, int q) { } // Invalid signature

public void myInvalidMethod2(int i=1, int q, int r=8) { } // Invalid signature





Reason for the Change

It does not make sense to have non-default parameters follow default parameters. In such cases all calls to the method must provide an explicit value for the default parameter, and the parameter could never take its default. Therefore it understandable that .NET CIL does not support such cases. Starting in AX 2012 the X++ compiler no longer supports such cases either, to be compatible with CIL.



3. Methods that Override Should Match the Parent Signature

When a method in a derived class has the same name as a method in its base class, the X++ compiler requires the exact same parameter signature for the two methods. Also, both methods must have the exact same return type. Otherwise the derived class will fail to compile.

For example, in AX 2012 under AOT > Classes, the X++ abstract class SysAttribute is extended by the class SrsReportNameAttribute. Therefore an instance of SrsReportNameAttribute can be passed to a method that takes a parameter of type SysAttribute. But for overriding a method, these two types would not be considered an exact match, and the X++ compiler would not consider these two types to be the exact same kind of parameter or return type.

In the following X++ code example, the MyDerivedClasswould fail to compile:

// X++

class MyBaseClass
{
protected void getAttribute(SysAttribute _sysAttrib) { }
}



class MyDerivedClass extends MyBaseClass
{
protected void getAttribute(SrsReportNameAttribute _srsReportNameAttrib)
{ } //will not compile
}


Further, no default parameter can exactly match a non-default parameter, or vice verse. The number of parameters must also match. X++ supports method overriding, but not method overloading.

These rules also apply when a class implements an interface.

Reason for the Change

Without this new restriction enforced by the X++ compiler, these incompatibility errors would be detected only during run time. The above X++ code example would compile in AX 2009, but in AX 2012 the X++ compiler will reject this example.



4. Interface Implementation Must be Complete

An X++ class that implements an interface must provide code for all the methods of the interface. This includes any methods the interface inherits from another interface.

In the following X++ code example, BadClass fails to compile in AX 2012:

// X++

interface IF1
{
void method3();
}

interface IF2 extends IF1
{
void method4();
}

class BadClass implements IF2 // Fails to compile, is missing method3.
{
public void method4()
{ }
}




Reason for the Change

Same as for item 3 above.



5. The Same Method Name cannot be Inherited from both Base Class and Interface

Suppose a derived class both extends a base class and implements an interface. And suppose that the base class and the interface specify the same method name. The X++ compiler no longer tolerates this situation.

In the following X++ code example, the SadClass class fails to compile in AX 2012:

// X++

abstract class YourClass
{
void method5() { }
}

interface YourIF
{
void method5() { }
}

// SadClass fails to compile, because the name 'method5' is inherited twice.

class SadClass extends YourClass implements YourIF
{
public void method5()
{
info("Hello World.";)
}
}




Reason for the Change

Same as for item 3 above.






Источник: http://blogs.msdn.com/b/x/archive/20...s-ax-2012.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11
dynamics-ax: Interview with Microsoft's Lachlan Cash on his new role, AX 2012 and more Blog bot DAX Blogs 6 22.04.2011 14:55
axinthefield: Dynamics AX Event IDs Blog bot DAX Blogs 0 01.03.2011 22:11
daxdilip: Whats New in Dynamics AX 2012 (A brief extract from the recently held Tech Conf.) Blog bot DAX Blogs 7 31.01.2011 12:35
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 13:05.