@@ -141,7 +141,19 @@ class ReturnTypeVerifier {
141141
142142 void reportTypeError () {
143143 String displayName = enclosingExecutable.element.displayName;
144- if (displayName.isEmpty) {
144+ if (enclosingExecutable.isConstructor) {
145+ var constructor = enclosingExecutable.element as ConstructorElement ;
146+ var className = constructor.enclosingElement.displayName;
147+ var constructorBaseName = constructor.displayName;
148+ var constructorName = constructorBaseName.isEmpty
149+ ? className
150+ : '$className .$constructorBaseName ' ;
151+ _errorReporter.reportErrorForNode (
152+ StaticTypeWarningCode .RETURN_OF_INVALID_TYPE_FROM_CONSTRUCTOR ,
153+ expression,
154+ [S , T , constructorName],
155+ );
156+ } else if (displayName.isEmpty) {
145157 _errorReporter.reportErrorForNode (
146158 StaticTypeWarningCode .RETURN_OF_INVALID_TYPE_FROM_CLOSURE ,
147159 expression,
@@ -237,7 +249,19 @@ class ReturnTypeVerifier {
237249
238250 void reportTypeError () {
239251 String displayName = enclosingExecutable.element.displayName;
240- if (displayName.isEmpty) {
252+ if (enclosingExecutable.isConstructor) {
253+ var constructor = enclosingExecutable.element as ConstructorElement ;
254+ var className = constructor.enclosingElement.displayName;
255+ var constructorBaseName = constructor.displayName;
256+ var constructorName = constructorBaseName.isEmpty
257+ ? className
258+ : '$className .$constructorBaseName ' ;
259+ _errorReporter.reportErrorForNode (
260+ StaticTypeWarningCode .RETURN_OF_INVALID_TYPE_FROM_CONSTRUCTOR ,
261+ expression,
262+ [S , T , constructorName],
263+ );
264+ } else if (displayName.isEmpty) {
241265 _errorReporter.reportErrorForNode (
242266 StaticTypeWarningCode .RETURN_OF_INVALID_TYPE_FROM_CLOSURE ,
243267 expression,
0 commit comments