Skip to content

Commit 9d6243e

Browse files
committed
CLJCLR-175: Fix aset throwing an exception when arg is type Array by inference (say from aclone).
1 parent 3b87270 commit 9d6243e

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

Clojure/Clojure/Lib/RT.cs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ static Dictionary<Symbol, Type> CreateDefaultImportDictionary()
5252

5353
static IEnumerable<Type> GetAllTypesInNamespace(string nspace)
5454
{
55-
Func<Assembly, IEnumerable<Type>> getTypes = (Assembly a) => {
55+
Func<Assembly, IEnumerable<Type>> getTypes = (Assembly a) =>
56+
{
5657
try { return a.GetTypes(); } catch (Exception) { return new Type[0]; }
5758
};
5859
var q = AppDomain.CurrentDomain.GetAssemblies()
@@ -74,7 +75,7 @@ static IEnumerable<Type> GetAllTypesInNamespace(string nspace)
7475

7576
public static readonly object[] EmptyObjectArray = new Object[] { };
7677

77-
static readonly RTProperties _versionProperties = new RTProperties();
78+
static readonly RTProperties _versionProperties = new();
7879

7980
public static RTProperties GetVersionProperties() { return _versionProperties; }
8081

@@ -83,7 +84,7 @@ static IEnumerable<Type> GetAllTypesInNamespace(string nspace)
8384
// for folks using Cygwin and its ilk.
8485
public const string ClojureLoadPathString = "CLOJURE_LOAD_PATH";
8586

86-
static public readonly Object REQUIRE_LOCK = new Object();
87+
static public readonly Object REQUIRE_LOCK = new();
8788

8889
#endregion
8990

@@ -123,7 +124,7 @@ public static readonly Namespace ClojureNamespace
123124
public static readonly Keyword TagKey
124125
= Keyword.intern(null, "tag");
125126

126-
public static readonly Keyword ParamTagsKey
127+
public static readonly Keyword ParamTagsKey
127128
= Keyword.intern(null, "param-tags");
128129

129130
public static readonly Keyword ConstKey
@@ -336,7 +337,7 @@ public override object invoke(object arg1)
336337

337338
static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
338339
{
339-
AssemblyName asmName = new AssemblyName(args.Name);
340+
AssemblyName asmName = new(args.Name);
340341
var name = asmName.Name;
341342
var stream = GetEmbeddedResourceStream(name, out _);
342343
if (stream == null)
@@ -371,16 +372,16 @@ static RT()
371372

372373
// TODO: Check for existence of ClojureContext.Default before doing this?
373374

374-
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
375-
LanguageSetup lsetup = new LanguageSetup(
375+
ScriptRuntimeSetup setup = new();
376+
LanguageSetup lsetup = new(
376377
typeof(ClojureContext).AssemblyQualifiedName,
377378
ClojureContext.ClojureDisplayName,
378379
ClojureContext.ClojureNames.Split(new Char[] { ';' }),
379380
ClojureContext.ClojureFileExtensions.Split(new Char[] { ';' }));
380381

381382

382383
setup.LanguageSetups.Add(lsetup);
383-
ScriptRuntime env = new ScriptRuntime(setup);
384+
ScriptRuntime env = new(setup);
384385
env.GetEngine("clj");
385386

386387

@@ -2375,7 +2376,7 @@ public static object[] toArray(object coll)
23752376

23762377
private static object[] IEnumToArray(IEnumerable e)
23772378
{
2378-
List<object> list = new List<object>();
2379+
List<object> list = new();
23792380
foreach (object o in e)
23802381
list.Add(o);
23812382

@@ -2503,7 +2504,7 @@ public static bool suppressRead()
25032504

25042505
static public string printString(object x)
25052506
{
2506-
using (StringWriter sw = new StringWriter())
2507+
using (StringWriter sw = new())
25072508
{
25082509
print(x, sw);
25092510
return sw.ToString();
@@ -2519,7 +2520,7 @@ static public Object readString(String s)
25192520

25202521
static public Object readString(String s, Object opts)
25212522
{
2522-
using (PushbackTextReader r = new PushbackTextReader(new StringReader(s)))
2523+
using (PushbackTextReader r = new(new StringReader(s)))
25232524
return LispReader.read(r, opts);
25242525
}
25252526

@@ -2784,7 +2785,7 @@ public static Type classForName(string p)
27842785

27852786
AppDomain domain = AppDomain.CurrentDomain;
27862787
Assembly[] assys = domain.GetAssemblies();
2787-
List<Type> candidateTypes = new List<Type>();
2788+
List<Type> candidateTypes = new();
27882789

27892790
// fast path, will succeed for namespace qualified names (returned by Type.FullName)
27902791
// e.g. "UnityEngine.Transform"
@@ -2864,9 +2865,9 @@ public static int alength(Array a)
28642865
}
28652866

28662867

2867-
public static Array aclone(Array a)
2868+
public static object aclone(Array a)
28682869
{
2869-
return (Array)a.Clone();
2870+
return a.Clone();
28702871
}
28712872

28722873

@@ -3141,7 +3142,7 @@ public static long nanoTime()
31413142
return DateTime.Now.Ticks * 100;
31423143
}
31433144

3144-
private static readonly Stopwatch _stopwatch = new Stopwatch();
3145+
private static readonly Stopwatch _stopwatch = new();
31453146

31463147
public static object StartStopwatch()
31473148
{
@@ -3209,7 +3210,7 @@ public static void SortArray(Array a, IFn fn)
32093210

32103211

32113212

3212-
static readonly Random _random = new Random();
3213+
static readonly Random _random = new();
32133214

32143215

32153216
public static double random()
@@ -3363,7 +3364,7 @@ private static bool TryLoadFromEmbeddedResource(string relativePath, string asse
33633364

33643365
var embeddedCljName = relativePath.Replace("/", ".") + ".cljr";
33653366
var stream = GetEmbeddedResourceStream(embeddedCljName, out Assembly containingAssembly);
3366-
if ( stream == null )
3367+
if (stream == null)
33673368
{
33683369
embeddedCljName = relativePath.Replace("/", ".") + ".cljc";
33693370
stream = GetEmbeddedResourceStream(embeddedCljName, out containingAssembly);
@@ -3401,12 +3402,12 @@ public static void LoadCljScript(string cljname, bool failIfNotFound)
34013402
{
34023403
FileInfo cljInfo = FindFile(cljname);
34033404
if (cljInfo != null)
3404-
LoadScript(cljInfo,cljname);
3405+
LoadScript(cljInfo, cljname);
34053406
else if (failIfNotFound)
34063407
throw new FileNotFoundException(String.Format("Could not locate Clojure resource on {0}", ClojureLoadPathString));
34073408
}
34083409

3409-
public static void LoadScript(FileInfo cljInfo, string relativePath)
3410+
public static void LoadScript(FileInfo cljInfo, string relativePath)
34103411
{
34113412
using (TextReader rdr = cljInfo.OpenText())
34123413
LoadScript(cljInfo.FullName, cljInfo.Name, rdr, relativePath);
@@ -3419,7 +3420,7 @@ private static void LoadScript(string fullName, string name, TextReader rdr, str
34193420

34203421
private static void Compile(FileInfo cljInfo, string relativePath)
34213422
{
3422-
using ( TextReader rdr = cljInfo.OpenText() )
3423+
using (TextReader rdr = cljInfo.OpenText())
34233424
Compile(cljInfo.Directory.FullName, cljInfo.Name, rdr, relativePath);
34243425
}
34253426

@@ -3450,7 +3451,7 @@ static IEnumerable<string> GetFindFilePathsRaw()
34503451
yield return Path.GetDirectoryName(typeof(RT).Assembly.Location);
34513452

34523453
Assembly assy = Assembly.GetEntryAssembly();
3453-
if ( assy != null )
3454+
if (assy != null)
34543455
yield return Path.GetDirectoryName(assy.Location);
34553456

34563457
string rawpaths = (string)System.Environment.GetEnvironmentVariable(ClojureLoadPathString);
@@ -3470,7 +3471,7 @@ public static FileInfo FindFile(string fileName)
34703471
foreach (string path in GetFindFilePaths())
34713472
{
34723473
fi = FindFile(path, fileName);
3473-
if (fi is not null ) return fi;
3474+
if (fi is not null) return fi;
34743475
}
34753476

34763477
return FindRemappedFile(fileName);
@@ -3490,11 +3491,11 @@ public static FileInfo FindRemappedFile(string fileName)
34903491
if (!(x is PersistentVector mapping) || mapping.length() < 2) continue;
34913492
if (!(mapping[0] is string nsRoot)) continue;
34923493
nsRoot = nsRoot.Replace('.', '/');
3493-
if(fileName.StartsWith(nsRoot))
3494+
if (fileName.StartsWith(nsRoot))
34943495
{
34953496
var fsRoot = mapping[1] as string;
34963497
var probePath = ConvertPath(fsRoot) + ConvertPath(fileName.Substring(nsRoot.Length));
3497-
if(File.Exists(probePath))
3498+
if (File.Exists(probePath))
34983499
return new FileInfo(probePath);
34993500
}
35003501
}
@@ -3621,7 +3622,7 @@ public static string[] TrimTrailingEmptyStrings(string[] arr)
36213622
break;
36223623
i--;
36233624
}
3624-
Array.Resize(ref arr,i + 1);
3625+
Array.Resize(ref arr, i + 1);
36253626
return arr;
36263627
}
36273628

0 commit comments

Comments
 (0)