diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties
index b7ba437d00f4..e6769e78a436 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties
@@ -376,3 +376,4 @@ declared.type.0.have.to.extend.script=Declared type ''{0}'' does not extend 'gro
base.script.annotation.is.allowed.only.inside.scripts=Annotation @BaseScript can only be used within a script
0.expressions.on.trait.fields.properties.are.not.supported.in.traits={0} expressions on trait fields/properties are not supported in traits
only.traits.expected.here=Only traits are expected here
+anonymous.classes.cannot.be.created.from.traits=Anonymous classes cannot be created from traits
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java
index 1c0b4c3a7771..b6c50c7cbeed 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java
@@ -2001,9 +2001,13 @@ public class GroovyAnnotator extends GroovyElementVisitor {
final GroovyConfigUtils configUtils = GroovyConfigUtils.getInstance();
if (typeDefinition.isAnonymous()) {
if (!configUtils.isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY1_7)) {
- holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("anonymous.classes.are.not.supported",
- configUtils
- .getSDKVersion(typeDefinition)));
+ holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(),
+ GroovyBundle.message("anonymous.classes.are.not.supported", configUtils.getSDKVersion(typeDefinition)));
+ }
+
+ PsiElement superClass = ((PsiAnonymousClass)typeDefinition).getBaseClassReference().resolve();
+ if (superClass instanceof GrTypeDefinition && ((GrTypeDefinition)superClass).isTrait()) {
+ holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("anonymous.classes.cannot.be.created.from.traits"));
}
}
else if (typeDefinition.getContainingClass() != null && !(typeDefinition instanceof GrEnumTypeDefinition)) {
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy
index e884bf3367ae..6e4a00604bd7 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy
@@ -1868,6 +1868,14 @@ trait C {
x++
}
}
+''')
+ }
+
+ void testTraitAsAnonymous() {
+ testHighlighting('''
+trait T {}
+
+new T(){}
''')
}
}