Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid modifying protected elements (#8512)
- Add check that protected elements are not modified. - Refactor out the visibility propagation from Inst.instExtends to a separate function and do it earlier, so that elements have the correct visibility when applying modifiers.
- Loading branch information
Showing
13 changed files
with
234 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// name: ProtectedMod2 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
model A | ||
protected Real x = 1.0; | ||
end A; | ||
|
||
model ProtectedMod2 | ||
extends A(x = 2.0); | ||
end ProtectedMod2; | ||
|
||
// Result: | ||
// class ProtectedMod2 | ||
// protected Real x = 2.0; | ||
// end ProtectedMod2; | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// name: ProtectedMod3 | ||
// keywords: | ||
// status: incorrect | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
model A | ||
protected Real x = 1.0; | ||
end A; | ||
|
||
model B | ||
A a; | ||
end B; | ||
|
||
model ProtectedMod3 | ||
extends B(a(x = 2.0)); | ||
end ProtectedMod3; | ||
|
||
// Result: | ||
// Error processing file: ProtectedMod3.mo | ||
// [flattening/modelica/scodeinst/ProtectedMod3.mo:9:13-9:25:writable] Error: Protected element ‘x‘ may not be modified, got ‘x = 2.0‘. | ||
// | ||
// # Error encountered! Exiting... | ||
// # Please check the error message and the flags. | ||
// | ||
// Execution failed! | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// name: ProtectedMod4 | ||
// keywords: | ||
// status: incorrect | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
model A | ||
protected Real x = 1.0; | ||
end A; | ||
|
||
model B = A; | ||
|
||
model ProtectedMod4 | ||
B b(x = 1.0); | ||
end ProtectedMod4; | ||
|
||
// Result: | ||
// Error processing file: ProtectedMod4.mo | ||
// [flattening/modelica/scodeinst/ProtectedMod4.mo:9:13-9:25:writable] Error: Protected element ‘x‘ may not be modified, got ‘x = 1.0‘. | ||
// | ||
// # Error encountered! Exiting... | ||
// # Please check the error message and the flags. | ||
// | ||
// Execution failed! | ||
// endResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// name: ProtectedMod5 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
model A | ||
Real x = 1.0; | ||
end A; | ||
|
||
model B | ||
protected | ||
A a; | ||
end B; | ||
|
||
model ProtectedMod5 | ||
extends B(a(x = 2.0)); | ||
end ProtectedMod5; | ||
|
||
// Result: | ||
// class ProtectedMod5 | ||
// protected Real a.x = 2.0; | ||
// end ProtectedMod5; | ||
// endResult |
Oops, something went wrong.