OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart2js.resolution.constructors; | 5 library dart2js.resolution.constructors; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/resolution.dart' show Feature; | 8 import '../common/resolution.dart' show Feature; |
9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
10 import '../constants/constructors.dart' | 10 import '../constants/constructors.dart' |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 MessageKind.NOT_A_TYPE, {'node': node}, error.name, error); | 712 MessageKind.NOT_A_TYPE, {'node': node}, error.name, error); |
713 registry.registerFeature(Feature.THROW_RUNTIME_ERROR); | 713 registry.registerFeature(Feature.THROW_RUNTIME_ERROR); |
714 } | 714 } |
715 return new ConstructorResult.forError(ConstructorResultKind.INVALID_TYPE, | 715 return new ConstructorResult.forError(ConstructorResultKind.INVALID_TYPE, |
716 error, new MalformedType(error, null)); | 716 error, new MalformedType(error, null)); |
717 } | 717 } |
718 | 718 |
719 ConstructorResult constructorResultForType(Node node, DartType type, | 719 ConstructorResult constructorResultForType(Node node, DartType type, |
720 {PrefixElement prefix}) { | 720 {PrefixElement prefix}) { |
721 String name = type.name; | 721 String name = type.name; |
722 if (type.isMalformed) { | 722 if (type.isMalformed) { |
Johnni Winther
2016/05/23 12:50:41
If you move `if (type.isTypeVariable) ...` before
eernst
2016/05/23 14:30:24
Done.
| |
723 return new ConstructorResult.forError( | 723 if (type is MalformedType) { |
724 ConstructorResultKind.INVALID_TYPE, type.element, type); | 724 return new ConstructorResult.forError( |
725 ConstructorResultKind.INVALID_TYPE, type.element, type); | |
726 } else { | |
727 // GENERIC_METHODS: This block provides thin support for generic | |
728 // methods: If a method type variable is used as a constructor, a | |
729 // warning is issued and code for a runtime error generated. | |
730 assert(type is MethodTypeVariableType); | |
731 MethodTypeVariableType methodTypeVariableType = type; | |
732 reporter.reportWarningMessage( | |
733 node, | |
734 MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, | |
735 { 'typeVariableName': methodTypeVariableType.name}); | |
736 registry.registerFeature(Feature.THROW_RUNTIME_ERROR); | |
737 return new ConstructorResult.forError( | |
738 ConstructorResultKind.INVALID_TYPE, | |
739 methodTypeVariableType.toMalformedElement, | |
740 methodTypeVariableType); | |
741 } | |
725 } else if (type.isInterfaceType) { | 742 } else if (type.isInterfaceType) { |
726 return new ConstructorResult.forType(prefix, type); | 743 return new ConstructorResult.forType(prefix, type); |
727 } else if (type.isTypedef) { | 744 } else if (type.isTypedef) { |
728 return reportAndCreateErroneousConstructorElement( | 745 return reportAndCreateErroneousConstructorElement( |
729 node, | 746 node, |
730 ConstructorResultKind.INVALID_TYPE, | 747 ConstructorResultKind.INVALID_TYPE, |
731 type, | 748 type, |
732 resolver.enclosingElement, | 749 resolver.enclosingElement, |
733 name, | 750 name, |
734 MessageKind.CANNOT_INSTANTIATE_TYPEDEF, | 751 MessageKind.CANNOT_INSTANTIATE_TYPEDEF, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 // constructors. | 866 // constructors. |
850 return null; | 867 return null; |
851 } | 868 } |
852 // TODO(johnniwinther): Use [Name] for lookup. | 869 // TODO(johnniwinther): Use [Name] for lookup. |
853 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 870 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
854 if (constructor != null) { | 871 if (constructor != null) { |
855 constructor = constructor.declaration; | 872 constructor = constructor.declaration; |
856 } | 873 } |
857 return constructor; | 874 return constructor; |
858 } | 875 } |
OLD | NEW |