From f4be48ff7e81f464e446623753e14a5f5c861424 Mon Sep 17 00:00:00 2001 From: Michael Lill Date: Thu, 12 Sep 2024 10:30:45 +0200 Subject: [PATCH] fe: library feature current, use thisType of selfType see also Current: ``` public Current(SourcePosition pos, AbstractFeature f) { super(f.thisType()); ... } ``` I found this bug while trying to persist the main application to fum-file then reload it from there. --- src/dev/flang/fe/LibraryFeature.java | 2 +- src/dev/flang/fe/LibraryModule.java | 17 ++++++++++------- src/dev/flang/fe/Module.java | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/dev/flang/fe/LibraryFeature.java b/src/dev/flang/fe/LibraryFeature.java index 8c9cc80a0e..77d32a9576 100644 --- a/src/dev/flang/fe/LibraryFeature.java +++ b/src/dev/flang/fe/LibraryFeature.java @@ -615,7 +615,7 @@ AbstractBlock code(int at, Stack s, int pos, int posEnd) } case Current: { - x = new AbstractCurrent(selfType()) + x = new AbstractCurrent(selfType().asThis()) { public SourcePosition pos() { return LibraryFeature.this.pos(fpos, fposEnd); } }; break; } diff --git a/src/dev/flang/fe/LibraryModule.java b/src/dev/flang/fe/LibraryModule.java index 6049c410a3..e9dbd3480d 100644 --- a/src/dev/flang/fe/LibraryModule.java +++ b/src/dev/flang/fe/LibraryModule.java @@ -101,7 +101,7 @@ public class LibraryModule extends Module implements MirModule * The base index of this module. When converting local indices to global * indices, the _globalBase will be added. */ - final int _globalBase; + private final int _globalBase; /** @@ -113,19 +113,19 @@ public class LibraryModule extends Module implements MirModule /** * The module intermediate representation for this module. */ - MIR _mir; + private MIR _mir; /** * Map from offset in _data to LibraryFeatures for features in this module. */ - TreeMap _libraryFeatures = new TreeMap<>(); + private final TreeMap _libraryFeatures = new TreeMap<>(); /** * Map from offset in _data to LibraryType for types in this module. */ - TreeMap _libraryTypes = new TreeMap<>(); + private final TreeMap _libraryTypes = new TreeMap<>(); /** @@ -141,7 +141,7 @@ public class LibraryModule extends Module implements MirModule /** * Cache for innerFeatures created from given index */ - Map> _innerFeatures = new TreeMap<>(); + private final Map> _innerFeatures = new TreeMap<>(); /** @@ -153,13 +153,13 @@ public class LibraryModule extends Module implements MirModule /** * The universe */ - final AbstractFeature _universe; + private final AbstractFeature _universe; /** * Modules referenced from this module */ - final ModuleRef[] _modules; + private final ModuleRef[] _modules; /** @@ -375,6 +375,9 @@ AbstractFeature libraryFeature(int offset) */ AbstractFeature feature(int offset) { + if (PRECONDITIONS) require + (offset >= -1); + return (offset == -1) ? null : (offset == 0) ? universe() diff --git a/src/dev/flang/fe/Module.java b/src/dev/flang/fe/Module.java index dbdc9aaf68..62ce7455f7 100644 --- a/src/dev/flang/fe/Module.java +++ b/src/dev/flang/fe/Module.java @@ -52,7 +52,7 @@ /** * A Module represents a Fuzion module independently of whether this is loaded - * from source code, library from a .mir file or downloaded from the web. + * from source code, library from a .fum file or downloaded from the web. * * @author Fridtjof Siebert (siebert@tokiwa.software) */ @@ -159,7 +159,7 @@ protected static void add(SortedMap> s, Featu /** - * Create SourceModule for given options and sourceDirs. + * Create Module for given options and sourceDirs. */ Module(LibraryModule[] dependsOn) {