File tree Expand file tree Collapse file tree 5 files changed +18
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 5 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,8 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
166166 TypeSpliceInValPatternID ,
167167 ModifierNotAllowedForDefinitionID ,
168168 CannotExtendJavaEnumID ,
169- InvalidReferenceInImplicitNotFoundAnnotationID
169+ InvalidReferenceInImplicitNotFoundAnnotationID ,
170+ TraitMayNotDefineNativeMethodID
170171
171172 def errorNumber = ordinal - 2
172173}
Original file line number Diff line number Diff line change @@ -1480,6 +1480,13 @@ import ast.tpd
14801480 def explain = " "
14811481 }
14821482
1483+ class TraitMayNotDefineNativeMethod (sym : Symbol )(
1484+ implicit ctx : Context )
1485+ extends SyntaxMsg (TraitMayNotDefineNativeMethodID ) {
1486+ def msg = em """ A trait cannot define a ${hl(" @native" )} method. """
1487+ def explain = " "
1488+ }
1489+
14831490 class OnlyClassesCanHaveDeclaredButUndefinedMembers (sym : Symbol )(
14841491 implicit ctx : Context )
14851492 extends SyntaxMsg (OnlyClassesCanHaveDeclaredButUndefinedMembersID ) {
Original file line number Diff line number Diff line change @@ -467,6 +467,8 @@ object Checking {
467467 if (sym.hasAnnotation(defn.NativeAnnot )) {
468468 if (! sym.is(Deferred ))
469469 fail(NativeMembersMayNotHaveImplementation (sym))
470+ else if (sym.owner.is(Trait ))
471+ fail(TraitMayNotDefineNativeMethod (sym))
470472 }
471473 else if (sym.is(Deferred , butNot = Param ) && ! sym.isType && ! sym.isSelfSym) {
472474 if (! sym.owner.isClass || sym.owner.is(Module ) || sym.owner.isAnonymousClass)
Original file line number Diff line number Diff line change 1+ -- [E159] Syntax Error: tests/neg/i9432.scala:2:14 ---------------------------------------------------------------------
2+ 2 | @native def foo(x: Int): Unit // error
3+ | ^
4+ | A trait cannot define a @native method.
Original file line number Diff line number Diff line change 1+ trait CLibrary {
2+ @ native def foo (x : Int ): Unit // error
3+ }
You can’t perform that action at this time.
0 commit comments