File tree 5 files changed +18
-1
lines changed
compiler/src/dotty/tools/dotc
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] {
166
166
TypeSpliceInValPatternID ,
167
167
ModifierNotAllowedForDefinitionID ,
168
168
CannotExtendJavaEnumID ,
169
- InvalidReferenceInImplicitNotFoundAnnotationID
169
+ InvalidReferenceInImplicitNotFoundAnnotationID ,
170
+ TraitMayNotDefineNativeMethodID
170
171
171
172
def errorNumber = ordinal - 2
172
173
}
Original file line number Diff line number Diff line change @@ -1480,6 +1480,13 @@ import ast.tpd
1480
1480
def explain = " "
1481
1481
}
1482
1482
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
+
1483
1490
class OnlyClassesCanHaveDeclaredButUndefinedMembers (sym : Symbol )(
1484
1491
implicit ctx : Context )
1485
1492
extends SyntaxMsg (OnlyClassesCanHaveDeclaredButUndefinedMembersID ) {
Original file line number Diff line number Diff line change @@ -467,6 +467,8 @@ object Checking {
467
467
if (sym.hasAnnotation(defn.NativeAnnot )) {
468
468
if (! sym.is(Deferred ))
469
469
fail(NativeMembersMayNotHaveImplementation (sym))
470
+ else if (sym.owner.is(Trait ))
471
+ fail(TraitMayNotDefineNativeMethod (sym))
470
472
}
471
473
else if (sym.is(Deferred , butNot = Param ) && ! sym.isType && ! sym.isSelfSym) {
472
474
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