parsing - Dart2JS编译器无法编译代码。这是错误,功能还是局限性?

标签 parsing compiler-construction dart standards-compliance maturity

我使用Dart2JS编译器版本1.0.0_r30798(稳定)。

示例代码(仅用于介绍问题):

此处的真实代码(现已针对dart2js行为进行了更正):https://github.com/mezoni/queries/blob/master/lib/src/queries/lookup.dart

这是
Queryable collections for Dart language

class ILookup<TKey, TElement> implements IEnumerable<IGrouping<TKey, TElement>> {
}

class Lookup<TKey, TElement> extends Object with Enumerable implements ILookup<TKey, TElement> {
}

class IEnumerable<T> implements HasIterator<T> {
}

class HasIterator<T> {
}

class IGrouping<TKey, TElement> implements IEnumerable<TKey> {
}

class Enumerable<T> implements IEnumerable<T> {
}

void main() {
  var obj = new Lookup();
  print(obj);
}

此代码会产生以下Google Dart dart2js编译器错误:

 Internal Error: Inheritance of the same class with different type arguments is not
 supported: Both HasIterator<dynamic> and HasIterator<IGrouping<TKey, TElement>> are
 supertypes of Lookup<TKey, TElement>.
 class Lookup<TKey, TElement> extends Object with Enumerable implements ILookup<TKey,
 TElement> {

 ^^^^^
 Error: Compilation failed.

也就是说,dart2js编译器无法编译此代码。

因此,我无法理解:“这是错误,功能还是局限性?”。

最佳答案

首先,dart2js不是适用语言规范的Dart VM编译器。由于Dart VM和Javascript是不同的语言,因此在非常抽象的极端情况下可能会发生不同的行为或限制。他们不应该,但是他们应该。

话虽这么说,但我不明白为什么此代码首先可以在VM中运行。根据我对Dart中的继承和mixins的了解,您对Lookup的定义应如下所示:

class Lookup<TKey, TElement> extends Object with Enumerable<IGrouping<TKey, TElement>> implements ILookup<TKey, TElement>`

因为否则,如错误消息所述,您将使用不同的类型参数两次继承HasIterator,这当然是一个小问题-如果最终向HasIterator添加方法,应调用这两个方法中的哪一个? method1(dynamic)method1(IGrouping<TKey, TElement>)

关于parsing - Dart2JS编译器无法编译代码。这是错误,功能还是局限性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21077398/

相关文章:

compiler-construction - 如何在 LLVM 中声明全局变量?

android - flutter - 使用抽屉子部件 onTap 更改子部件

java - Android:提取两个 HTML 标签之间的文本

node.js - 从 JSON 文件读取并解析原始数据

C++ 字符串字面量数据类型存储

Dart 程序没有退出

flutter - 添加 ListView 构建器时,整个屏幕变为空白

用户提供的C++解析方程

parsing - 有没有办法在不使用语法引导翻译的情况下编写编译器前端?