Skip to content

Commit

Permalink
GH-2230: Incorrect scoping in modules containing (non-static) polyfil…
Browse files Browse the repository at this point in the history
…ls (#2231)

* fix bug

* add tests

* adjust test expectation
  • Loading branch information
mmews-n4 authored Oct 18, 2021
1 parent 3dc450a commit 2b9bdaa
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class LocallyKnownTypesScopingHelper {
if (local === null || local.eIsProxy) {
return parent;
}
val eoDescrs = local.topLevelTypes.map[ topLevelType | EObjectDescription.create(topLevelType.name, topLevelType) ];
val eoDescrs = local.topLevelTypes.filter[t | !t.polyfill ].map[ topLevelType | EObjectDescription.create(topLevelType.name, topLevelType) ];
return scopeSnapshotHelper.scopeFor("scopeWithLocallyDeclaredTypes", script, parent, eoDescrs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class StaticPolyfill_inheriting_from_filled_type__IdeTest extends AbstractStatic
"(Error, [17:14 - 17:18], Couldn't resolve reference to IdentifiableElement 'test'.)",
"(Error, [21:11 - 21:15], Couldn't resolve reference to IdentifiableElement 'test'.)",
"(Error, [27:34 - 27:39], Couldn't resolve reference to Type 'Buddy'.)",
"(Error, [29:20 - 29:24], Couldn't resolve reference to Type 'Poly'.)",
"(Error, [36:8 - 36:12], Couldn't resolve reference to IdentifiableElement 'test'.)"
],
"src2/A2.n4js" -> #[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2021 NumberFour AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* NumberFour AG - Initial API and implementation
*/

/* XPECT_SETUP org.eclipse.n4js.xpect.tests.N4jsXtTest
Workspace {
Project "ref-to-filled-type-scoping" {
Folder "src" {
ThisFile { }
}
File "package.json" { from="ref_to_filled_type_scoping.package.json" }
}
}
END_SETUP
*/


@@Global @@ProvidedByRuntime

@Polyfill
export external public class Array<T> extends Array<T> {
// XPECT linkedFragment at 'Array' --> n4scheme:/builtin_js.n4jsd#/1/@topLevelTypes.2
member: Array<number>; // correctly scoped to Array in builtin_js.n4jsd
}

// XPECT linkedFragment at 'Array' --> n4scheme:/builtin_js.n4jsd#/1/@topLevelTypes.2
const K : Array<string> = null;

class SomeClass {
// XPECT linkedFragment at 'Array' --> n4scheme:/builtin_js.n4jsd#/1/@topLevelTypes.2
someMethod(): Array<string>; // make sure: not incorrectly scoped to Array in this module
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "ref-to-filled-type-scoping",
"version": "0.0.1",
"n4js": {
"projectType": "runtimelibrary",
"vendorId": "org.eclipse.n4js",
"vendorName": "Eclipse N4JS Project",
"output": "src-gen",
"sources": {
"source": [
"src"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2021 NumberFour AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* NumberFour AG - Initial API and implementation
*/

@@StaticPolyfillAware

export public class A {
public methodA() : void {}
}


export public class B {
public methodB() : void {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2021 NumberFour AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* NumberFour AG - Initial API and implementation
*/

/* XPECT_SETUP org.eclipse.n4js.xpect.tests.N4jsXtTest
Workspace {
Project "ref-to-static-filled-type-scoping" {
Folder "src1" {
ThisFile { }
}
Folder "src2" {
File "ref_to_static_filled_type_scoping.n4js" { from="ref_to_static_filled_type_scoping.n4js.src2" }
}
File "package.json" { from="ref_to_static_filled_type_scoping.package.json" }
}
}
END_SETUP
*/




@@StaticPolyfillModule

@StaticPolyfill
export public class A extends A {

// XPECT linkedFragment at 'A' --> ../src2/ref_to_static_filled_type_scoping.n4js#/1/@topLevelTypes.0
public member : A = null;
}


@StaticPolyfill
export public class B extends B {

// XPECT linkedFragment at 'A' --> ../src2/ref_to_static_filled_type_scoping.n4js#/1/@topLevelTypes.0
public member : A = null;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "ref-to-static-filled-type-scoping",
"version": "0.0.1",
"n4js": {
"projectType": "library",
"vendorId": "org.eclipse.n4js",
"vendorName": "Eclipse N4JS Project",
"output": "src-gen",
"sources": {
"source": [
"src1",
"src2"
]
}
}
}

0 comments on commit 2b9bdaa

Please sign in to comment.